embedded resource file not found in assembly

S

Steve Richter

I am embedding an xml file in my class library assembly.

In solution explorer I right click a folder, add , new item, xml file.

then on the xml file I right click, properties, build action =
embedded resource.

build the class library, run the following code to access the XML as a
stream:
Stream cmdsStream =
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"AutoCoder.Ftp.FtpCommands.xml");

get back null. as in the resource stream is not found.

so I go back to the class library project, rebuild all, and use
ObjectBrowser to display the contents of the assembly. I dont see the
xml embedded resource file. Looking everywhere, starting from the
namespace of the folder I placed the file in.

Did I embed the file incorrectly?

thanks,

-Steve
 
N

Nicholas Paldino [.NET/C# MVP]

Steve,

You need to indicate a namespace for the file. Take a look at the
"Application" tab in the project properties. Look at the "Default
Namespace" textbox. That namespace is what you have to append before the
"AutoCoder.Ftp.FtpCommands.xml" string in order to be able to retrieve the
stream to your resource.

If you look at your compiled binary in Reflector, you will see that the
file does exist as a resource, with that namespace specified.

Hope this helps.
 

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