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

后端 未结 3 1841
逝去的感伤
逝去的感伤 2020-12-10 19:20

I\'m developing a localisable application. In my \"local\" resource file, I\'ve the language used by default (english) and if possible, I load the user\'s preference and cul

相关标签:
3条回答
  • 2020-12-10 20:09

    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);
    
    0 讨论(0)
  • 2020-12-10 20:09

    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

    0 讨论(0)
  • 2020-12-10 20:12

    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());
    
    0 讨论(0)
提交回复
热议问题