Getting Started with Windows Phone 8 Apps Development


Source :

This post covers basic steps to help you get started developing apps for Windows Phone 8.  First I discuss the prerequisites for installation of the development environment and finish up with some common errors I’ve encountered . Its written based on my experience developing Trivia Monkey for Windows Phone .

A Couple of Prerequisites Before Your Start

Windows 8.0 + OS Requirements.

Interestingly enough, you cannot develop windows phone 8 apps on a machine running any operating systems below windows 8. You WILL need to install the Windows 8 OS in order to install the Windows Phone 8 SDK.

Hyper -V + SLAT Compliant Processor Requirement for running the Emulator

Haven’t got a Windows Phone 8 test device (the Nokia lumia series are awesome) ? Then you need to know this. You cannot run the Windows Phone 8 Emulator on a processor architecture that does not support Hyper V and SLAT architecture. Previous emulators (Windows phone 7.x ) will run on previous windows but you really dont want to target the old OS versions. An excerpt from the microsoft website below details more on this.

Windows Phone 8 Emulator runs as a virtual machine on Hyper-V, the virtualization technology for Windows 8. To run the emulator, your computer must meet the requirements to run Hyper-V as described in this topic.
The setup program tries to configure these prerequisites for you silently when you install the SDK. When setup successfully configures the prerequisites, the emulator simply works as expected. Otherwise you may have to enable these prerequisites manually. If you have to configure the prerequisites manually, the steps and tools are described in How to enable Hyper-V for the Windows Phone Emulator.

Luckily, I had a device so I didn’t really bother slugging out the above emulator issue. More on getting the emulator to run can be found here . Goodluck

Getting Started

Download and Install the SDK

Download the Windows Phone SDK from here. I was expecting it to update my already installed Visual Studio 2013 Ultimate, but instead it installed standalone. No problem .

Debugging Your App on a Device

Attach a windows phone device via usb (I used the Nokia Lumia 820) and it gets automatically detected by windows 8 and the appropriate drivers installed. Created your  first App – (New Project > Windows Phone >  ) and click the green play button to deploy on device. This will likely throw an error – launch failed because the windows phone 8 device is developer locked. And that brings us to the next point.

Unlock Device for Developer Testing

Each device needs to be unlocked for developer testing. You can do that by following the instructions at this link . If  the developer lock error still persist, ensure the device date and time are correct and you should be good to go.

Getting Some Sample Code

Windows phone 8 apps can be written in VB.NET or C# in conjunction with xaml for UI layout. I tend to favour C# especially given its close similarity with Java. You can find some sample code on the MSDN Code Gallery.

Some Common Errors I encountered and Fixes

Error 1 This operation returned because the timeout period expired. 0 0

Cause : The above error occurs sometimes when I try to deploy to a device.
Fix : Change usb port in use, disconnect devices, close visual studio , reopen and deploy again.

Error 2 System.UnauthorizedAccessException: Invalid cross-thread access ..

Cause : Many times it is desirable to run some heavy code in the background. For example when building a game, whenever a game session is over, there is alot of housekeeping to be done. Update the database with scores, points, achievements, post to leaderboards etc. These activities may take a few seconds to conclude and its best to allow the user proceed with other UI interactions while these are done in a background thread. This is the basis of asynchronous programming and its simply a lovely concept. I noticed that after the background thread finished executing and I tried to update the UI (e.g set the value of a text box or update a databinding for some datatemplated control), I got the following unauthorized error above. It appears threads are not allowed to meddle into one anothers business.

Fix : Use the Dispatcher.BeginInvoke method to perform the update in the UI thread. So you surround your update code with this ..

 Deployment.Current.Dispatcher.BeginInvoke(() =>
    // Your code
}) ;

Error 3 Nullreference for xaml defined control

Cause : Changes to your Xaml user interface file are done without cleaning the project.
Fix : Whenever you make a change to a xaml file, you must clean and rebuild the project for the compiler to rebuild those components. E.g whenever you change your ui elements and access them in code, you must clean and rebuild the project.

Error 4 Wp8 app works on local device or emulator but crashes when downloaded from App store ..

Fix : Force culture localization  on your date and double variables. Also test for null variables.
This error was a really tough one. My app worked flawlessly on my local test devices , but kept crashing each time I downloaded it from the App store and tried to install. The best way to debug this is to download the crash reports from your dev center apps dashboard and inspect its content.  In my case, I had some values that were null for new users and this went undetected on my test device. Tough luck. Some windows phone debugging steps can be found here

About Vykthur

Mobile and Web App Developer and Researcher. Passionate about learning, teaching, and recently - writing.
This entry was posted in Developer Tips, Microsoft, Programming, Windows Phone 8 and tagged , , , , . Bookmark the permalink.