Reflection / Resource file issue

  • Thread starter Thread starter John Spiegel
  • Start date Start date
J

John Spiegel

Hi all,

I've been banging my head trying to figure out what I'm missing here. I
downloaded a control that uses a stream derived from a bitmap file. What I
can't seem to figure out is where it's getting its location for the bmp.
Physically, it is located in a Resources\Images folder under the project
root. In the project, this same folder structure is referenced (so the
treeview shows a Resources folder containing an Images subfolder and the
bitmap contained within).

The example then uses
Assembly.GetManifestResourceStream("MyNameSpace.Resources.Images.MyFile.bmp");

When I attempt to duplicate this functionality, the above function returns a
stream of an "<undefined value>". I've checked names, compared the resx
files and directory structures with no luck. I've done very little with
reflection and resource files so am probably missing something stupid.

Any suggestions?

Thanks,

John
 
Firstly, the name is case sensitive, so make sure your case matches.

Secondly, the folder structure in the project is not reflected in the
resource name. Generally, you would use the root namespace of the
project followed by the image name such as: MyNameSpace.MyFile.bmp,
being sure to match the case.

Hope this helps
 
Hi Chris,

Thanks for the tips. I've checked the case and tried a number of variations
on NameSpace.FileName.bmp, but still no luck.

- John
 
John said:
The example then uses
Assembly.GetManifestResourceStream("MyNameSpace.Resources.Images.MyFile.bmp");

When I attempt to duplicate this functionality, the above function returns a
stream of an "<undefined value>". I've checked names, compared the resx
files and directory structures with no luck. I've done very little with
reflection and resource files so am probably missing something stupid.

1) As has been mentioned, "MyFile.bmp" will be qualified by the
assembly's default namespace. (Assembly.GetManifestResourceNames()
will return all named resources in an assembly.)

2) The bitmap MUST be an "Embedded Resource" (Solution Explorer /
Properties / Build Action). When you add an image, it defaults to
"Content".
 
Back
Top