This has been driving me insane since the start of the month.
I am attempting to retrieve globalised values from resource files within a C# ASP.NET web application in VS 2008 targeting .NET 3.5. I have added two files to the App_GlobalResources directory:
- WebUI.resx
- WebUI.en-US.resx
both of which have corresponding .designer.cs files generated by the GlobalResourceProxyGenerator tool. They both have a string entry called MyString and 'Embedded Resource' has been set for their build action.
The default namespace and assembly name for the application is MyApp.WebUI, but the .designer.cs files seem to ignore this and uses the namespace Resources instead.
In the standard ASPX page, all is well when attempting to retrieve values from the resource files but I am struggling to retrieve the same values explicitly from code using the following:
1 ResourceManager rm = new ResourceManager(typeof(Resources.WebUI).ToString(), Assembly.GetExecutingAssembly());
2 string myLocalisedString = rm.GetString(Resources.WebUI.MyString);
I am receiving the following error on line 2:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Resources.WebUI.resources" was correctly embedded or linked into assembly "MyApp.WebUI" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Using my favourite search engine to find a solution resulted in many suggestions, but I cannot manage to get any of them to resolve the issue. These include:
- Renaming the resource files to match the default namespace (which interestingly changes the namespace of the .designer.cs files to Resources.Namespace rather then Namespace.Resources)
- Removing and re-adding the resource files (oh, the joys of TFS source control)
- Using the full namespace to the resources in the ResourceManager constructor (i.e. MyApp.WebUI.WebUI)
- ...many others along the same lines as the above
Typically, the relevant MSDN pages/examples aren't very helpful either.
In my bin directory, I have the following (relevant) files:
- bin/MyApp.WebUI.dll
- bin/MyApp.WebUI.pdb
- bin/en-US/MyApp.WebUI.resources.dll
When I open the bin/MyApp.WebUI.dll file in ildasm.exe I can see Resources > Resources.WebUI > MyString etc. When I open bin/en-US/MyApp.WebUI.resources.dll I can't see any entries which is because the .designer.cs file seems to be empty [I have only just noticed this while preparing this essay - is this a bug with .culture.resx files?].
Please can someone suggest what else I can try to attempt to resolve this issue? I believe at least one of the items above is a bug in VS 2008, but am sure there must be something else basic that I am doing wrong here.
Thanks in advance!
Marc