There are three potential gotchas when using resources:
(1) VS.NET insists on adding in your project's default namespace name for
any resource you embed in this way.
(2) Some things use assembly manifest resources, some use localizable
resource files (ResourceManager). It isn't necessarily clear from the
documentation which will be used for any given example.
(3) Case sensitivity.
First, check (3). Try running your component through ILDASM. If you look
in the MANIFEST you should see all of the embedded resources listed. This
will tell you what Visual Studio elected to call your resource. Make sure
that name matches the string you are using, and has the right case.
Anakrino solves most instances of (2), and it tells us that in this case, it
is looking for an assembly manifest resource. Which leaves us with (1) as
the problem.
Note that this Bitmap constructor will actually prepend the namespace of
whatever Type you pass in. So if this code is in a class that is in some
namespace other than the project namespace, that could be messing you up.
Make sure that you pass in a Type object for a type in the project's default
namespace. (And it must also be defined in the assembly that contains the
resource - the Type object you pass in serves two roles: naming and assembly
specification.)
If all else fails you can do this:
Bitmap bmp = new Bitmap (GetType().Assembly.GetManifestResourceStream(
"MyNamespace.MyBmp.bmp");
This uses the Bitmap(Stream) constructor, and manually gets the
explicitly-named manifest resource from the assembly - it reduces the scope
for ambiguity.
It would be nice if you could get VS.NET to let you call your embedded
resources what you want to call them. Does anyone know if there is a way of
doing this? (Other than nant, or nmake...)
--
Ian Griffiths
DevelopMentor
----- Original Message -----
From: "Luis Abreu" <[EMAIL PROTECTED]>
> well I want to include a bitmap in a c# windows app. I've just checked
> the book programming windows wicth c# and the writer says that the
> only things one must do is change the properties of the file for
> embededresource and then load the bitmap using something like this:
>
> Bitmap b = new Bitmap( GetType(), "Bitmap1.bmp"); //in this case i
> have removed the resource namespace of the project.
>
> however, when I run the app i get an exception saying that the
> resource can't be found.
>
> so, what am i doing wrong?
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.