Problem loading embedded resource

D

Drew

Assembly asm = Assembly.GetExecutingAssembly();

me = new Bitmap(asm.GetManifestResourceStream("me.gif"));

I have used this before without any problem, but now I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll

Additional information: 'null' is not a valid value for 'stream'.

I've got the Build Action for me.gif set as Embedded Resource.

Argh!

Why can't it find the file?

Thnx!

Drew
 
1

100

Hi Drew,
Probably the the full name of the resource is not right. Use ILDasm to see
the actual name of the resource.
Normaly resources are named
<Default Namespace>[.<subdir>].<resource-file name>

where
*Default Namespace* is the one set in the project properties.
*subdir* if any is in the casses where you keep resource files in different
forlders under your project.
*<resource-file name>* is the name of the resource files.

But my suggestion is to use ILDasm to see the name of the resources. You can
find them in MANIFEST node in the main screen

HTH
B\rgds
100
 
D

Drew

OK, it looks like I just forgot to include the namespace
when trying to read the embedded resource. :)

Now, I just want to remove the namespace altogether
in Visual Studio, but just removing the namespace from
the code doesn't seem to do the trick.

What else has to be done to remove the namespace?

Drew




100 said:
Hi Drew,
Probably the the full name of the resource is not right. Use ILDasm to see
the actual name of the resource.
Normaly resources are named
<Default Namespace>[.<subdir>].<resource-file name>

where
*Default Namespace* is the one set in the project properties.
*subdir* if any is in the casses where you keep resource files in different
forlders under your project.
*<resource-file name>* is the name of the resource files.

But my suggestion is to use ILDasm to see the name of the resources. You can
find them in MANIFEST node in the main screen

HTH
B\rgds
100
Drew said:
Assembly asm = Assembly.GetExecutingAssembly();

me = new Bitmap(asm.GetManifestResourceStream("me.gif"));

I have used this before without any problem, but now I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll

Additional information: 'null' is not a valid value for 'stream'.

I've got the Build Action for me.gif set as Embedded Resource.

Argh!

Why can't it find the file?

Thnx!

Drew
 
1

100

Hi Drew,
The only way I can thing of is to go in Project | <prj name> Properties |
General and delete the *Default Namespace* and rebuild the project. Anyway,
I don't thing is a good idea because that *Default Namespace* is used by the
IDE when generates classes, forms, etc. If you delete this property you have
to add the namespaces for the latter by hand. Thus, better decorate you
resource names with the namespace when you read the resources. Otherwie
IMHO the pain will be bigger.

B\rgds
100

Drew said:
OK, it looks like I just forgot to include the namespace
when trying to read the embedded resource. :)

Now, I just want to remove the namespace altogether
in Visual Studio, but just removing the namespace from
the code doesn't seem to do the trick.

What else has to be done to remove the namespace?

Drew




100 said:
Hi Drew,
Probably the the full name of the resource is not right. Use ILDasm to see
the actual name of the resource.
Normaly resources are named
<Default Namespace>[.<subdir>].<resource-file name>

where
*Default Namespace* is the one set in the project properties.
*subdir* if any is in the casses where you keep resource files in different
forlders under your project.
*<resource-file name>* is the name of the resource files.

But my suggestion is to use ILDasm to see the name of the resources. You can
find them in MANIFEST node in the main screen

HTH
B\rgds
100
Drew said:
Assembly asm = Assembly.GetExecutingAssembly();

me = new Bitmap(asm.GetManifestResourceStream("me.gif"));

I have used this before without any problem, but now I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll

Additional information: 'null' is not a valid value for 'stream'.

I've got the Build Action for me.gif set as Embedded Resource.

Argh!

Why can't it find the file?

Thnx!

Drew
 
D

Drew

This seems to work pretty good:

asm.GetManifestResourceStream(asm.GetName().Name+ ".me.gif")

So, turns out it's not really the namespace it wants but the Assembly Name?

I actually tried making the Default Namespace blank in the project
properties but that didn't help.

Would I have to remove the Assembly name in the project properties to be
able to eliminate the naming decoration?

Drew

100 said:
Hi Drew,
The only way I can thing of is to go in Project | <prj name> Properties |
General and delete the *Default Namespace* and rebuild the project. Anyway,
I don't thing is a good idea because that *Default Namespace* is used by the
IDE when generates classes, forms, etc. If you delete this property you have
to add the namespaces for the latter by hand. Thus, better decorate you
resource names with the namespace when you read the resources. Otherwie
IMHO the pain will be bigger.

B\rgds
100

Drew said:
OK, it looks like I just forgot to include the namespace
when trying to read the embedded resource. :)

Now, I just want to remove the namespace altogether
in Visual Studio, but just removing the namespace from
the code doesn't seem to do the trick.

What else has to be done to remove the namespace?

Drew




100 said:
Hi Drew,
Probably the the full name of the resource is not right. Use ILDasm to see
the actual name of the resource.
Normaly resources are named
<Default Namespace>[.<subdir>].<resource-file name>

where
*Default Namespace* is the one set in the project properties.
*subdir* if any is in the casses where you keep resource files in different
forlders under your project.
*<resource-file name>* is the name of the resource files.

But my suggestion is to use ILDasm to see the name of the resources.
You
can
find them in MANIFEST node in the main screen

HTH
B\rgds
100
Assembly asm = Assembly.GetExecutingAssembly();

me = new Bitmap(asm.GetManifestResourceStream("me.gif"));

I have used this before without any problem, but now I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll

Additional information: 'null' is not a valid value for 'stream'.

I've got the Build Action for me.gif set as Embedded Resource.

Argh!

Why can't it find the file?

Thnx!

Drew
 
1

100

Hi Drew,
I actually tried making the Default Namespace blank in the project
properties but that didn't help.
It worked for me. When I removed *Default Assembly* and rebuild the project
the resources didn't have "decorations" anymore.
Would I have to remove the Assembly name in the project properties to be
able to eliminate the naming decoration?

No you can't remove the assembly name because this is the name the compiler
will give to the executable.
The *Default Assembly* is what the IDE uses for resources.

Did you keep your resources in a sub-folder under the the project's main
folder. In this case IDE will add the sub-folder name before the resource
file name. In this case AFAIK you can't do anything but put the resources in
the main folder.
Check the "Build Action" for the resources. It has to be "Embedded Resource"

B\rgds
100
Drew

100 said:
Hi Drew,
The only way I can thing of is to go in Project | <prj name> Properties |
General and delete the *Default Namespace* and rebuild the project. Anyway,
I don't thing is a good idea because that *Default Namespace* is used by the
IDE when generates classes, forms, etc. If you delete this property you have
to add the namespaces for the latter by hand. Thus, better decorate you
resource names with the namespace when you read the resources. Otherwie
IMHO the pain will be bigger.

B\rgds
100

Drew said:
OK, it looks like I just forgot to include the namespace
when trying to read the embedded resource. :)

Now, I just want to remove the namespace altogether
in Visual Studio, but just removing the namespace from
the code doesn't seem to do the trick.

What else has to be done to remove the namespace?

Drew




Hi Drew,
Probably the the full name of the resource is not right. Use ILDasm
to
see
the actual name of the resource.
Normaly resources are named
<Default Namespace>[.<subdir>].<resource-file name>

where
*Default Namespace* is the one set in the project properties.
*subdir* if any is in the casses where you keep resource files in
different
forlders under your project.
*<resource-file name>* is the name of the resource files.

But my suggestion is to use ILDasm to see the name of the resources. You
can
find them in MANIFEST node in the main screen

HTH
B\rgds
100
Assembly asm = Assembly.GetExecutingAssembly();

me = new Bitmap(asm.GetManifestResourceStream("me.gif"));

I have used this before without any problem, but now I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll

Additional information: 'null' is not a valid value for 'stream'.

I've got the Build Action for me.gif set as Embedded Resource.

Argh!

Why can't it find the file?

Thnx!

Drew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top