Monday, February 16, 2009

Public Global Resources

In VS 2008, the addition of a resources (.resx) file to the App_GlobalResources file defaults the custom tool to GlobalResourceProxyGenerator.  This tool generate a class (resource_file.designer.cs) that is internal (friend in VB), therefore classes outside of the web project assembly cannot access these resources.  The solution is to simply change the custom tool from GlobalResourceProxyGenerator to PublicResXFileCodeGenerator in the properties of the resx files.  This tool will create a publicly accessible in the designer file; however, it will also default the namespace to WebProjectName.App_GlobalResources. If you put "Resources" into the Custom Tool Namespace property of the resx file, you will be able to recompile without any problems, and your resources will be accessible outside of the web project's assembly.

One last note, it is my experience that you must also set the Build Action to "Embedded Resource" or you will receive an MissingManifestResourceException in your consuming web project at runtime.


WolfyUK said...

Excellent tip, thanks!

Helped me resolve this issue.

Anders √ėyvind said...

Great, Cristopher, this helped me big time!