Missing Resource

Because I know you can’t find sensible information when you leave the confines of predefined behavior in your favorite IDE (whichever that may be, none is without flaws) I sometimes like to share seemingly straightforward errors that end up engulfing my time.

The story starts with me adding an icon to a button as well as a number of other modifications to a windows forms ui (C++/CLI), modifications that in the end convinced the runtime that it should crash without any warning. I quickly went through the first three stages of debugging and deduced that the culprit was a MissingManifestResourceException that crashed the app because it couldn’t find the image I just added.

Apart from not making much sense (if any) as the resource was added with the UI designer, I could only conclude that this was some sort of particularity that was escaping me at the moment so I started looking on the internet and to my surprise most people seemed to believe that this happened because they separated the implementation from the .h file generated by visual studio, a solution that I tried and that failed miserably I might add (which is in a way a pity because if it turned out to be because of that, this little story would have been a lot more hilarious), but seeing as there was no plausible explanation for I moved some code to another file so my program can’t find a resource by name, I instructed visual studio to break on CLR exceptions and started looking into the error, and then it hit me.

Obviously sometime during the implementation I decided that the name of the namespace that had the UI wasn’t descriptive enough and felt like changing it. Now when you don’t have anything kept in the .resx file that’s just fine and you wouldn’t even notice that the compiler now generates and embeds a wrong .resources file because of course, these things are accessed by the fully qualified name Namespace.Classname.resource, but while I changed the namespace in the .h file, visual studio thought that the resource file should still use the old namepace name (default namespace).

The actual fix of course took less than a minute, but it was the journey that mattered;

TL;DR if your C++/CLI application crashes because it can’t find a resource check resource file (output directory) has the same namespace and when in doubt delete .resoure files and rebuild the soulution.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s