Monday, April 23, 2018

UNIT TEST in ASP.Net MVC Part II - How to handle App_GlobalResources


Traditional ASP.Net approaches to Localization and Internationaliazation is to use one special App_GlobalResources folder to hold resource files and Visual Studio will use GlobalResourceProxyGenerator to generate a strongly typed internal class to wrap all internal resources.

Note those global resources are not embeded inside the project dll file. They actually were stored inside one special assembly named App_GlobalResources.dll so that the ASP.Net views can reference them. This is fine but the problem is the special assembly was created by ASP.Net runtime, there is no such assembly during the compilation, thus when you tried to execute your unit testing against the resources, following error will happen:

"Could not load file or assembly 'App_GlobalResources' or one of its dependencies. The system cannot find the file specified.":"App_GlobalResources" System.IO.IOException {System.IO.FileNotFoundException}

The solution is to create one custom folder for your MVC project and put your resource files to that folder. For each resource file, update the file property as following:


The reason to change the Custom Tool to PublicResXFileCodeGenerator is because this tool will make the resource file available for your ASP.Net views. Alternately, you can also set the resource file to public inside the resource editor to do the same job.

Resource Files and ASP.NET MVC Projects

No comments:

Post a Comment