简体   繁体   中英

Why can't I access a .resx file as an embedded resource?

I would like to write some code which can access my RESX files as embedded resources, load them as XML documents and perform some analysis on them (eg checking for duplicate nodes).

Note that I'm not trying to access them as collections of resources, but as the underlying XML files.

The following code:

using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
    using (StreamReader streamReader = new StreamReader(stream))
    {
        returnText = streamReader.ReadToEnd();
    }
}

...fails (returning null for the stream variable), when precisely the same code, referencing a text file in the same directory as the .resx file, succeeds. So it seems that GetManifestResourceStream() appears to deliberately ignore .resx files.

Can anyone suggest why, or what I might do about it?

I am able to get the embeddeb resx resource in a Silverlight project:

string resourceName = "/MyAssemby;component/MyResource.resx";
using (XmlReader reader = XmlReader.Create(resourceName))
{ ... }

but fails in other projects, like in the Test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM