Groups | Blog | Home
all groups > dotnet clr > may 2004 >

dotnet clr : Load Resources from Dynamicly loaded assemblies


Patrik Löwendahl
5/21/2004 4:52:05 PM
Hi,

I've got an application that uses Assembly.LoadFrom and
Activator.CreateInstance to dynamicly load assemblies and create objects.
Tese assemblies containes classes which exposes a property, ItemImage.
ItemImage returns an Image object.

The image (icon) it should represent is embedded in the assembly as a
resource and browsable through reflecor.

When trying to retrieve the image through the standard resource reading
code:

<code>
Type thisType = this.GetType();
Assembly thisAssembly = Assembly.GetExecutingAssembly();
string iconName = thisType.ToString() + ".ico";
Stream imageStream = thisAssembly.GetManifestResourceStream(iconName);
Bitmap image = new Bitmap(imageStream);
return (Image)image;
</code>

the stream returned is always null. I've tried to hardcode the resource name
as displayed in reflector, no luck. I've also tried using GetEntryAssembly
and GetAssembly(thisType), still no luck.

What am I doing wrong?

--
Patrik Löwendahl
www.cshrp.net - "Elegant code by witty programmers"

Mattias Sjögren
5/21/2004 8:46:22 PM
Hej Patrik,

Does the code work correctly when the library is loaded the normal
way, not using Assembly.LoadFrom()?

Does thisAssembly.GetManifestResourceNames() return anything useful?



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
rogertan NO[at]SPAM online.microsoft.com
6/14/2004 9:00:54 PM
Patrik, how are you embedding the icon? Are you talking about using the
/win32icon switch with csc.exe or al.exe? If so, I don't believe (from what
I know) the icon used is included when you reflect on the assembly. I
looked in ILDASM and couldn't see any trace of the icon file I used to
embed into an assembly.
AddThis Social Bookmark Button