C # Help to load external DLL PNG resources

1

I created the Dll of resources with I PNG in C # when I compile to read in PictureBox of Visual Studio I get news of NUll or missing System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

Assemblyasm=Assembly.LoadFrom(System.Environment.CurrentDirectory+@"\PNGRES.dll");
Stream strm = asm.GetManifestResourceStream("resources.PNG"+(string)asm.GetManifestResourceNames()[102]);
Bitmap b = (Bitmap)Image.FromStream(strm);
pictureBox1.Image = b;
    
asked by anonymous 03.02.2016 / 15:28

1 answer

1

The code is a bit different from yours, but this form should be revised, it's very simple when we add the reference in the project, but I did an example dynamically loading the dll .

The library is called: Biblioteca.dll , the resource (file .resx ) calls Imagens.resx , so the name to put it in the constructor class ResourceManager is Biblioteca.Imagens , as it is in the code. Within this resource there are 3 images with their names: _1 , _2 and _3 which in this case is the value of GetObject .

Having this value ( Object ), make a cast (Imagem) and pass the value to PictureBox1.Image that will load the image ...

string path = @"C:\Projetos\";
string real = System.IO.Path.Combine(path, @"Biblioteca.dll");

Assembly assembly = Assembly.LoadFrom(real);
ResourceManager resourceManager = new ResourceManager("Biblioteca.Imagens", assembly);
pictureBox1.Image = (Image)resourceManager.GetObject("_3");

Code Master Reference

    
10.09.2016 / 00:08