Reading RESX Content from the loaded DLL and NOT the RESX file
I need to be really clear on this. I am not trying to read the myfile.resx file. I am trying to read the content from the myresourcenamespace.myfile.dll.
My hopes is to create a dictionary of my KVPs contained within the RESX content, by accessing that which is preloaded into the DLLs. My current solution depends too much on the files exisiting and a bunch of copying to insure that files are where they need to be. The DLLs are more reliable at this point.
I have been able to gain access to the assembly via "new resourcemanager(myassembly开发者_开发百科type)", but I am stuck at this point. I cannot seem to read the actual content from memory. I continually run up against MissingManifestException when I try and access the content as a stream from the resource manager.
Here is my successful code:
var myType = Type.GetType("ViewRes.StaticMessages", true);
var myResManager = new ResourceManager("StaticMessages",
System.Reflection.Assembly.GetAssembly(myType));
Here is my failure code:
using (var fileReader = new ResXResourceSet(
myResManager.GetStream(myResManager.BaseName)))
{
//.... code read here
}
The ResXResourceSet throws the MissingManifestException. I have tried everything I can think of.
Instead of:
var myType = Type.GetType("ViewRes.StaticMessages", true);
var myResManager = new ResourceManager("StaticMessages",
System.Reflection.Assembly.GetAssembly(myType));
Try like this:
var myType = Type.GetType("ViewRes.StaticMessages", true);
var myResManager = new ResourceManager("StaticMessages", myType.Assembly);
// you could specify the desired culture for which you would like to get the
// resource values
var culture = CultureInfo.InvariantCulture;
var resourceSet = myResManager.GetResourceSet(culture, true, true);
now you can loop:
foreach (DictionaryEntry item in resourceSet)
{
var key = item.Key;
var value = item.Value;
}
精彩评论