Locating and matching resources in embedded and external resource files

Discussion in 'ASP .Net' started by Johann Blake, Dec 17, 2003.

  1. Johann Blake

    Johann Blake Guest

    I'm having trouble grasping how ASP.NET correctly locates resources.
    There is plenty of documentation on this subject but some things are
    not clear at all.

    In my ASP.NET application, I have multiple web forms. When you compile
    the application, it creates a DLL. If you view this DLL using ILDASM
    (the manifest), it shows info about the resources stored in the DLL.
    There is essentially an embedded resource "section" for each web form.
    The namespace used in each web form plays an important name in how the
    resource is named in the manifest. I call this a "section" because it
    is obviously referring to where the resources are located and not the
    actual resources stored there.

    At this point, the resources stored in the DLL are the "embedded
    resources". The default culture ID for the resources in the DLL is
    english US (en-US). The name of the DLL is myApp.dll.

    I also have an additional DLL that contains what I believe should be
    the resources translated over into German. The name of DLL resource
    file is
    myApp.de-DE.resources.dll. I say "believe" because I have no way of
    actually seeing the IDs of the resources in the original DLL. I assume
    that Visual Studio.NET uses the name of the controls found on the web
    forms as the ID in the resource. So I used these names as well as IDs
    in the German resource file.

    Finally, following the rules spelled out by Microsoft in their online
    documentation, you create subdirectories within the bin directory for
    resources and store the corresponding resource there.

    To read resources within the web form I do the following:

    Thread.CurrentThread.CurrentCulture = new
    CultureInfo(Session["CultureID"].ToString());
    Thread.CurrentThread.CurrentUICulture =
    Thread.CurrentThread.CurrentCulture;

    Assembly assembly = Assembly.Load("myApp");
    ResourceManager rm = new ResourceManager("myApp", assembly);
    this.lblCompanyID.Text = rm.GetString("lblCompanyID");

    I store the culture ID in the session and use it to set the current
    culture so that the correct resource will get loaded.

    When the culture is set to "de-DE", it will in fact load the correct
    resource.
    But when I set the culture to "en-US", it cannot find the resource. I
    really can't really understand why it even should find the resource.
    If the manifest indicated that resource in the english manifest was
    MyNamespace.NameOfWebForm.resources, I can't understand where ASP.NET
    even matches up resources. There doesn't appear to be any relationship
    here.

    If I were to create my German resources in a file called
    MyNamespace.NameOfWebForm.resources, it might work. But wait a second.
    Is this to imply that for every web form there must be a corresponding
    external resource file for the language you want to support? This
    doesn't make any sense. I thought that it was possible to store all
    resources for the entire ASP.NET application in one resource file
    myApp.de-DE.resources.dll and ASP.NET will take care of locating the
    corresponding resource in whatever resource is stored in the default
    manifest. And since there are multiple resource sections in the
    default assembly, doesn't it make sense that ASP.NET will know where
    to look?

    Regards,
    Johann Blake
     
    Johann Blake, Dec 17, 2003
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.