C # Custom attribute with support for string resources does not load localized resources
I have a DLL that contains these custom attributes
[AttributeUsage(AttributeTargets.Class)]
public class MyAttribute: System.Attribute {
private ResourceManager resManager = null;
public MyAttribute() {
}
public Type ResourceType { get; set; }
private string caption = string.Empty;
public string Caption {
get { return getResourceString(caption); }
set { caption = value; }
} //Caption
private string getResourceString(string resourceKey) {
if (string.IsNullOrWhiteSpace(resourceKey))
return string.Empty;
if (ResourceType == default(Type))
return resourceKey;
if (resManager == null)
resManager = new ResourceManager(ResourceType);
return resManager.GetString(resourceKey) ?? string.Format("[[{0}]]", resourceKey);
} //getResourceString()
}
And a program (exe) using MyAttribute as well as the required resources (resKeyHello) for English and French in Resources.resx and Resources.fr.resx respectively
[MyAttribute(Caption="resKeyHello", ResourceType=typeof(Resources)]
public Foo() {
}
The problem is that it never uses a satellite build. I also tried to create a ResourceManager like this ResourceManager (ResourceType.FullName, ResourceType.Assembly) , but without any effect. And also tried to load resource like this resManager.GetString (resourceKey, Thread.CurrentThread.CurrentUICulture)
In the debugger, I can see that CurrentUICulture is French.
source to share
I finally found a workaround.
The problem seems to be related to how the french resource file was created. I used Project -> New -> Resource file with the same name and .fr.resx extension.
The satellite DLL was generated at compile time in a subfolder. / bin / fr, but the runtime didn't see it.
Finally, I used the "ResX Resource Manager" from CodePlex to generate my resource files and now everything is fine
source to share