Reputation: 5899
I have an app that works just fine on my WinXP machine. However, when I try running it on my Win7 machine, it fails whenever it tries to load an embedded resource. The resources are all there (I can see them using Reflector).
The lines that fail are all of the form:
Splash.Image = new Bitmap(typeof(ContainerForm).Assembly.GetManifestResourceStream("SplashTest.Resources.Logo.gif"));
And they all fail with the same exception:
Exception='System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Stream stream)
I don't understand why this is not working on my Win7 machine but does on my usual WinXP dev machine.
Any ideas?
Upvotes: 2
Views: 298
Reputation: 941455
There are not a lot of possible failure modes here. Assembly.GetManifestResourceStream() will return null if the resource could not be found. That will make the Bitmap constructor fail with the indicated exception. Bit of a bug there, it should have thrown ArgumentNullException.
Anyhoo, it looks like for some reason the assembly doesn't get built with the bitmap resource on your XP machine. Double-check that with Ildasm.exe. Double-click Manifest, you should see the .mresource with the name you ask for.
The better mouse trap is to add the resource with Project + Properties, Resources tab, click the arrow on the Add Resource button, Add Existing File and navigate to the file. You can then reference the bitmap directly through the auto-generated property:
Splash.Image = Properties.Resources.Logo;
Upvotes: 1