Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« Where can I find Windows Phone Resources? | Main | Why does my XNA Game Not Fill the Screen? »
Monday
Apr122010

Why do I get an “Object reference not set to an instance of an object” error when I run my program?

image 
Scenes we don’t want to see…

Sometimes when you run a Windows Phone program from VS 2010 (usually one that has run successfully before) you get the above message.  This can also happen if you run a program that somebody else has sent you (and claims that it works).

The answer is simple, and has to do with the way that Visual Studio likes to create directory hierarchies as it builds your projects, and the fact that the filing system on your PC has a limited number of characters available for file paths. If you put your VS 2010 projects deep down your folders, in a well organised kind of way, they will fail to run as some of the files can’t be created, can’t be loaded and then produce the above error.

The solution is to move the entire project up a bit in the file system.

Reader Comments (3)

I've never seen this before (probably because I don't ever dev for windows phones), but that is possibly one of the most ridiculous errors ever. I get the feeling it wouldnt happen so easily in ext4 or hfs ;)
April 12, 2010 | Unregistered CommenterCalamari
Thank you for your post! I hope you don't mind, I blogged about it to (and gave you cred too).
http://www.pchenry.com/Home/tabid/36/EntryID/297/Default.aspx
April 13, 2010 | Unregistered CommenterPHenry
Rob, I've seen this error a couple of times. For me, right-clicking the WP7 project and select Debug- Start new instance, this will launch the application in the enumator.
May 17, 2010 | Unregistered CommenterNick

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.
Errors occurred while processing template[pageRendered/journalEntry.st]:
StringTemplate Error: Can't parse chunk: {settingHomePageKBArticle}" target="_blank">Learn how.</a></li>
<li>If you have already selected a front page, make sure it is enabled. Click on the Cubes icon (top right) and then click the "enable page" button.</li>
</ol>
</div>

: expecting '"', found '<EOF>'
StringTemplate Error: problem parsing template 'pageRendered/noDefaultModule': null
StringTemplate Error: problem parsing template 'pageRendered/noDefaultModule': null