C# - Cannot getting a string from ResourceManager (from satellite assembly)

人盡茶涼 提交于 2019-11-28 11:38:29

I found why, hope this will help someone that is in the same case.

So, I looked in MyApp_FR.dll the code generated to use the Resource file, it is :

new global::System.Resources.ResourceManager("MyApp_FR.Properties.Resources", typeof(Resources).Assembly);

but when retrieving the manifest file names, I got :

"MyApp_FR.Properties.Resources.resources"

Seems to be there is a .resource to much in this room... By removing it, I can use my ResourceManager normally, all works fine...

Final code :

Assembly resourceAssembly = Assembly.LoadFrom(resourceFileName);
string[] manifests = resourceAssembly.GetManifestResourceNames();
if (manifests.Length == 1)
{
    string manifest = manifests[0].Replace(".resources", string.Empty);
    manager = new ResourceManager(manifest, resourceAssembly);
}

// Works !
manager.GetString("PleaseCallIT", null);

From Microsoft Support:

This problem occurs if you use a localized resource that exists in a satellite assembly that you created by using a .resources file that has an inappropriate file name. This problem typically occurs if you manually create a satellite assembly:

Try this KB:

http://support.microsoft.com/kb/839861

An alternate approach, put in the following as test code:

string[] resources = 
    System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();

In debugging, check the contents of resources to see if it matches what you are loading with ResourceManager.

Especially note, if you get something like 'MyAssembly..Resources.resources', then you will need to explicitly add 'Resources' to the ResourceManager constructor:

    private static readonly ResourceManager stringTable =
 new ResourceManager("MyAssembly.Resources", Assembly.GetExecutingAssembly());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!