Reputation: 121
I have a solution with one web project and one class library. In web project I have App_GlobalResources folder with resource file. In code used in web project I can access resourcel like this: string r = Resources.res.ResourceString123;
How to get this resource string from class library?
Upvotes: 1
Views: 4492
Reputation: 335
I also use a separate assembly for my web project and class libraries. I required access to my App_GlobalResources in the web project for my ModelBinders. I access the resource is via this method (see: A Beginner's Guide to ASP.NET Application Folders).
HttpContext.GetGlobalResourceObject( string classKey , string resourceKey )
Once caveat is that you will need access to the HttpContext, which I have via the controllerContext in my ModelBinder.
My ModelBinder code reads as follows:
var errorMessage = controllerContext.HttpContext.GetGlobalResourceObject( "DefaultModelBinder" , "PropertyValueRequired" ) as string;
The above allows me to have a consistent error message across ASP.NET's default error messages and my ModelBinders, even though I have them in separate assemblies.
Upvotes: 1
Reputation: 5762
If using visual studio 2008 you can set the access modifier on the Resource designer to public
in the class library.
Upvotes: 0
Reputation: 6346
In .net 2.0, you will need to add the InternalsVisibleTo attribute to the assembly & set it to the namespace which needs to access the file:
Another options could be to create a class in the class library which can return the strings you need...
HTH.
Upvotes: 0