ResourceManager.GetString() method returns wrong string from different assemblies
Here is what was going on. I had an assembly with several translation resource files. These were all embedded resources.
When I compiled the assembly it was putting the default English inside its .dll. As for the other languages it was creating folders, fr, da, de, etc. with the languages in.
I had to move all these as well if I wanted them to be picked up by my main application which was loading in all these other assemblies. Thought as I told the assembly that they were all embedded resource files it would actually embed them!
I now have a AssemblyLoader
which loads all the required .dll's when it cant find them from their current locations, packaging it will be determined on whether I want to include all languages or select the ones I want before building the project. More work than I had hoped, but solved in the end.
Anyone have any question, feel free to ask.
Not sure how you are instantiating ResourceManager, but when you call ResourceManager.GetString(), you can specify CultureInfo, which helps you fetch the string in correct locale. So you can do something like:
var string = ResourceManager.GetString("ResourceKey", new CUltureInfo("en-GB"));
This will make sure that the string key is from the en-GB specific Resource file.
The first overload of GetString, ResourceManager.GetString(string)
, uses the current thread's CurrentUICulture (Thread.CurrentThread.CurrentUICulture
).
Referring to MSDN:-
The resource that is returned is localized for the UI culture of the current thread, as defined by the CurrentUICulture property.
In a background thread, do not assume the thread's CurrentUICulture is the same as your main (or UI) thread's CurrentUICulture.
A better way to access the resource from a background thread is to use something like the following to get the correct localised string:-
var localString = Properties.Resources.ResourceManager.GetString("ResourceKey", CultureInfo.CurrentCulture);