Porting to Mono

I came across an error while porting to Mono. It read: "Unhandled Exception: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture."

This is the long-winded story of how I solved the problem.

I've been developing in C# with Visual Studio for somewhere around two years now. I really like Visual Studio and .NET makes life so much easier. However recently I've become acutely aware of the folks who cannot run my programs because they are on Linux or OS X. I know Java's cross-platform and I'm fairly familiar with it, but there's still the matter of running a virtual machine on the client's box and actually converting all my code from C# to Java. Though they are similar enough, my code depends rather heavily on .NET and I really wasn't looking forward to porting.

Then I thought to myself: "You know, I've been hearing some really good things about Mono." After doing some research I decided to give it a try.

For those of you who have not heard, Mono is an open source, cross-platform implementation of .NET. It essentially allows one to port .NET code from Windows to Linux and OS X with more or less ease, depending on how far into COM objects and Win32 calls you've delved. The closer you stay to .NET proper the easier the conversion. In my case I was able to open my Visual Studio 2005 solution in MonoDevelop and compile right away. There was, however, one error and it's for this reason I'm writing.

The error I got was "Unhandled Exception: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture."

There are apparently a number of reasons this error could arise. In my case it was because for one reason or another my Resources.resx file was not being properly linked to the requesting form. I was trying to load an image from Resources.resx into an ImageBox control on a form called mainForm.cs.

I never figured out why Mono didn't like what I had in the first place, which was: this.logo.BackgroundImage = global::FriendBlastr_Stingr.Properties.Resources.logo;

I did manage to get it working though. All I did was copy the resource (in my case this just meant everything between the opening and closing data tags for that resource; in your case it might mean the assembly tags as well) from Resources.resx to mainForm.resx. There was no reason for that resource to be global anyway, so no harm no foul. Then I changed the line of code previously mentioned to:
this.logo.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.logo")));

(Note that I also changed the name of the resource in mainForm.resx from "logo" to "$this.logo" for consistency's sake.)

Now it works like a charm! :-)

1 comment for "Porting to Mono".

1. No bad post, write more

No bad post, write more