Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a resource file from a different project with ResourceManager C#

I have a Visual Studio solution consisting of multiple projects. In one of the projects, I have a languagelocalization resource file. I would like to access this file in code in a different project using ResourceManager. Normally when accessing a resource file in the same project I would use:

ResourceManager rm = new ResourceManager("Namespace.LanguageLocalization", Assembly.GetExecutingAssembly());

However when I use that same code in a different project, it can't find the resource file. I double checked to make sure this project is referenced by the project with the resource file and its declared in a using statement at the top of the class.

Any suggestions?

like image 331
Meyer Denney Avatar asked Mar 09 '12 20:03

Meyer Denney


1 Answers

The second argument to the ResourceManager constructor specifies the assembly that contains the resources. Assembly.GetExecutingAssembly() won't work because that returns the assembly for your other project. Instead, pass typeof(APublicClassInTheResourceAssembly).Assembly; any class in the resource assembly will do.

like image 180
Michael Liu Avatar answered Sep 24 '22 18:09

Michael Liu