Home All Groups Group Topic Archive Search About

Embedding resource files in CLASS LIBRARY

Author
9 Feb 2005 1:14 AM
Marcus

I need to embed a couple of XSL files in a .NET class library for deployment
reasons. I'd like to be able to just edit the source files and rebuild the
library to update the resources (ie no cumbersome multi-step procedure).

I found this page that shows how to do exactly what I want, but it is for
executables:
http://www.devx.com/dotnet/Article/10831/1954?pf=true

According to those instructions I added the files in the solution explorer
and set the build action to "embedded resource". However, I failed to access
the resources (which I realized the page also says, when checked again). See
code below. I can't see any resources in the DLL when I examine it with
ildasm.

StreamReader sr = new
StreamReader(Assembly.GetEntryAssembly().GetManifestResourceStream(name));
Fails with "Object reference is not set to an instance of an object"

Is there a way I can do this in a class library?

Thanks for any tips!
Marcus
Author
9 Feb 2005 6:41 AM
Mattias Sjögren
Marcus,

>StreamReader sr = new
>StreamReader(Assembly.GetEntryAssembly().GetManifestResourceStream(name));
>Fails with "Object reference is not set to an instance of an object"
>
>Is there a way I can do this in a class library?

GetEntryAssembly() returns the assembly that started the appdomain. In
a class library you probably want GetExecutingAssembly instead.



Mattias

--
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Are all your drivers up to date? click for free checkup

Author
9 Feb 2005 6:18 PM
Marcus
Yep, now it's working. Thanks!!!

Tack så mycket. ;)

Marcus


Show quoteHide quote
"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
news:euQsMInDFHA.4020@TK2MSFTNGP14.phx.gbl...
> Marcus,
>
>>StreamReader sr = new
>>StreamReader(Assembly.GetEntryAssembly().GetManifestResourceStream(name));
>>Fails with "Object reference is not set to an instance of an object"
>>
>>Is there a way I can do this in a class library?
>
> GetEntryAssembly() returns the assembly that started the appdomain. In
> a class library you probably want GetExecutingAssembly instead.
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.

Bookmark and Share

Post Thread options