Thursday, April 02, 2009

C# ResourceManager path

this is something that would have been nice for them to include on the MSDN page about the ResourceManager class in C#. a ResourceManager is used for localization b/c it allows you to read the right language string from .resx files that you've added to your application.

you may find that you get this error message when trying to read a string out of a resource file:

“Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"AppName.FileName.resources\" was correctly embedded or linked into assembly \"AppName\" at compile time, or that all the satellite assemblies required are loadable and fully signed.”

the trick here is that you must include the VS project folder in the path when you instantiate the ResourceManager object. So if my assembly is "AppName" and my resource file called "FileName.resx" is under a folder called "FolderName," then the syntax looks like this:

// Declare a Resource Manager for localized string resources
private ResourceManager resManager = new ResourceManager("AppName.FolderName.FileName", System.Reflection.Assembly.GetExecutingAssembly());

note that you shouldn't include the file extension for the resource file.

No comments: