Search code examples
c#visual-studioembedded-resource

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?


Solution

  • 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.