Reputation: 3509
I am trying to dynamically load images from the Resources folder but for some reason GetManifestResourceStream
returns null. This is what I wrote:
System.Reflection.Assembly asm;
asm = System.Reflection.Assembly.GetExecutingAssembly();
Bitmap bmp = new Bitmap(asm.GetManifestResourceStream("MyProject.Properties.Resources.Image.png"));
I've tried every method I found here, but it doesn't work. The path is correct, the file is there. I need to do this dynamically because depending on user permissions, different assemblies will be loaded. So basically I need two things:
How can this be done?
Upvotes: 1
Views: 214
Reputation: 14386
This usually means the resource name is incorrect. Load the assembly in ildasm, look at the manifest for ".mresources" sections and find the one you want to load.
If not, the call to GetExecutingAssembly returns the assembly containing the code currently executing, which may be different to the DLL that contains the resource. Use GetCallingAssembly to load it from a separate DLL instead.
To answer your questions above:
- Get a list with all the assemblies that were loaded
Use the AppDomain.GetAssemblies method, for example:
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
- Load an image corresponding to the loaded assembly into a Bitmap
Iterate through the assemblies looking for the resource using GetManifestResourceStream.
Upvotes: 1