.net Resource DLL with multiple resx files

て烟熏妆下的殇ゞ 提交于 2019-12-23 15:52:34

问题


I need to know the way to properly access strings and images from a resource DLL that has multiple resource files (.resx).

I have a very large project that I am working on and is composed of several winforms each with multiple panels. I am trying to tidy things up a bit by making each form has its own res file and limit the application to one resource DLL instead of multiple resource DLLs.

The problem is when I try and add a new resource file to my resource DLL and try to access a string, for example, that is being saved in the newly created resx file. ResourceManager return a null string.

Here is how I am creating my ResourceManager object and getting the string

static public string GetResourceString(string sStringName)
{     
System.Reflection.Assembly myDllAssembly = System.Reflection.Assembly.LoadFile(ResPath);
     string[] allResourcesinDLL = myDllAssembly.GetManifestResourceNames();
     ResourceManager ResInstance = new ResourceManager(allResourcesinDLL[0].Replace(".resources", string.Empty), myDllAssembly);

 return  ResInstance.GetString(sStringName);
}

Where ResPath is the path to my resource DLL and sStringName is the resource/string title.

I Am not sure if there is a way to specify the resx file to read from or if it should be handled in some other way. Please bear in mind that my application is compiled using the .net 2.0 framework so I am kinda limited to the APIs that I am able to use.

来源:https://stackoverflow.com/questions/12550354/net-resource-dll-with-multiple-resx-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!