Embedding resource files in CLASS LIBRARY

M

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
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top