Windows Phone 7 Beta: My Application Won’t Start After Renaming Project

Windows Phone 7 Beta: My Application Won’t Start After Renaming Project

Yesterday I lost an hour or so tracking down a bug whereby I hit F5/Run in Visual Studio to debug a Windows Phone application. I’d been happily doing this all morning, then I decided to rename my application. You’d have thought this was just a matter of renaming the project, assembly name, default namespace, class/xaml namespaces, xap file and assembly information (to make sure they’re all consistent, rather than because they’re necessarily required in order to rename the application). It turns out that I’d completely forgotten to set the Startup object to the new xap file. We’ll it wasn’t all my fault – I’ve since then created a new project, changed the namespace in app.xaml, app.xaml.cs, mainpage.xaml and mainpage.xaml.cs and tried (unsuccessfully) to get Visual Studio to let me select NewApplication.App to be the startup object (as you can see in this image). Remember that it’s is the class (typically App) that inherits from Application that is the startup object for a Windows Phone application.

image

The symptoms (and this is true if the Startup object is set to “(not set)” or to an incorrect app name) is that Visual Studio deploys the application but when it goes to invoke the application it fails, so Visual Studio returns to the not running state (no errors!). If you attempt to run the application on the emulator you get the same thing – application goes to launch then crashes (again no error message/warning).

The fix is quite simple – Build the Windows Phone application (which shouldn’t have any errors, although in my opinion there should be to point out that the startup object doesn’t match a valid class), then Unload the project (by right-clicking the project and selecting Unload Project as the image below suggests). All you need to do now is to reload the project by again right-clicking the project node and selecting Reload Project.

.image

If you open up the project properties page you should be able to select the correctly named app as the startup object.

Leave a Reply

Your email address will not be published. Required fields are marked *