Localized resources associated with class libaries RRS feed

  • Question

  • User1108651750 posted

    I am new to .NET. 

    I am developing a web app which I have architecture to include several class libaries (a BLL, a DAL and a few separate DLLs (assemblies) that provide various classes specific to my app).  I think I understand how to localize aspx pages with resx files but am not sure how to attach resources to my class libary DLLs (I have several class libaries that need to retrieve resources based on the culture of the thread that instantiates a class).

    Everything I find on the web on this subject seems to say to create .resource files in the main web app.  However, I want my resources to be associated with the class library assembly.

    How do I do this?

    Also, I read something about making sure the calling app has a SatelliteContractVersion attribute set up correctly so that it is 'allowed' to load resources from a satellite of a different assembly version # that it.  Does this apply to class library assemblies loading resources from satellites as well?

    Friday, January 27, 2006 2:54 PM

All replies

  • User1108651750 posted
    I just found something about .NET 2 allowing expressions like this Resources.<resource file>.<resource name> to access resources.  I tried it in my class library code and it didn't work (I knew it won't).  How do I tell my class library assembly about the resx files stored in the main app's App_GlobalResources directory?  If there was a way to do this programatically that would be great - I could do it in some sort of class library init code when the calling app starts up.
    Friday, January 27, 2006 5:28 PM
  • User-2041805088 posted
    This shouldn't require any effort at all. For instance, if your resource file was named Resource.resx and the resource was named ApplicationTitle, then you would declare Resources.Resource.ApplicationTitle. When you say it doesn't work, what happens?
    Friday, January 27, 2006 5:33 PM
  • User1108651750 posted

    Error 2 The name 'Resources' does not exist in the current context C:\Documents and Settings\Emmanuel\My Documents\Stratelogics\R and D\Projects\Kingsmere\Development\KingsmereBLL\AccountManagement.cs 115 31 KingsmereBLL

    This is the offending line of source in AccountManagement.cs:

    msg.FromAddress = Resources.MAIL.en.ActivationEmailFrom;

    The resource file is named MAIL.en.resx and is placed in the project's root.

    I have also tried "Resources.MAIL.ActivationEmailFrom;" and renaming the resource file to "MAIL.resx".

    I have "using Sytem.Resources" at top of file (not sure what you call that).

    Could it be that VS.2005 must know to compile .resx files found in the App_GlobalResources directory into class DLLs (so that Resources.<resource filename base>.<resource name> form can be used) but that when resx are included in a class library which doesn't have an App_GlobalResource dir, it doesn't do anything special with them.  But then I've only been using .NET and VS for a couple of months now.

    Friday, January 27, 2006 7:56 PM
  • User-2041805088 posted
    If you can't access it like that, then it looks like VS isn't seeing the App_GlobalResources directory and/or the resource file. How exactly is your applicaiton laid out (i.e. BLL in a seperate assembly / project, rest of code in another project / assembly, and both are part of the same project, etc.)?
    Friday, January 27, 2006 9:17 PM
  • User1108651750 posted

    My BLL is a separate project that is part of the same solution that includes the web app (there are other class library assemblies in my solution too).

    The root directory for my BLL DLL is a peer to the root for the web app.

    For what it's worth I know that the App_LocalResources dir works since I refer to Resources.<x>.<y> in some my web app's aspx.cs files.

    I just discovered a way to 'embed' a resource file (seems like it must be named Resources.resx) into the class library assembly (in the assembly properties resource table).  And I AM able to access the resources using the Resources.<resource name> thing.  However, this is not exactly what I need.  I need to create multiple versions for the various cultures I am supporting and I don't seem to be able to embed more that ONE embedded resource file.

    Friday, January 27, 2006 9:45 PM
  • User-2041805088 posted

    Have you tried using a ResourceManager?

    Resource Manager and ASP.NET

    Friday, January 27, 2006 9:49 PM
  • User1108651750 posted

    No.  I was so looking forward to the strong typing that I haven't.

    I'm going to keep trying  Thanks for the help.

    Friday, January 27, 2006 10:02 PM
  • User-2041805088 posted

    I really haven't done much with resources in .NET 2.0, but I'm sure it's possible to have strongly typed resources for your situation.

    Localization in ASP.NET 2.0

    Friday, January 27, 2006 10:10 PM
  • User1108651750 posted

    Ya, I gotta believe that it is possible.  The problem as I see it is that the facility in VS.2005 for auto-generating the class that allows me to access resources using "Resources" class members seems to be tied to the existance of the special "App_GlobalResources" and "App_LocalResources" directories.  And since these directories only exist in web apps, they fall outside of the scope of my solution's class library assemblies.

    All the resources on the web and MSDN assume that one is associating resources with a web app.  In my case it is a class library.

    Anybody got any ideas on how to get the benefits of the "Resources" class wrapping of resources (and the resulting intellisense) for multiple resources files (multiple cultures) associated with a class library assembly in .NET 2.0?

    I'm really stumped on this one!

    Friday, January 27, 2006 11:56 PM