logo       

Re: embedding resources for globalization (complete frustration): msg#00085

windows.devel.dotnet.web

Subject: Re: embedding resources for globalization (complete frustration)

It looks like as I'm calling the satellite assembly from a user
control, the fallback process to load the resources fails completely.
I tried also:

Dim a As [Assembly] =
[Assembly].LoadFrom(Page.MapPath("../en-US").ToString +
Path.DirectorySeparatorChar + "machinelocator.resources.dll")

Dim rm As ResourceManager = New
ResourceManager("machinelocator", a, Nothing)
Dim str As String = rm.GetString("errorMessage")

The Page.MapPath("../en-US").ToString + Path.DirectorySeparatorChar +
"machinelocator.resources.dll" returns the correct path to the
satellite assembly on the hard drive, however the LoadFrom method
fails to find any valid assembly there, throwing the exception:
ex.Message "File or assembly name machinelocator.resources.dll, or
one of its dependencies, was not found." String


:\

Lizet

On 6/13/05, lizet peña <lizet.pena@xxxxxxxxx> wrote:
> The dll with the resource inside has this on the manifest:
> .assembly machinelocator.resources
> {
> .hash algorithm 0x00008004
> .ver 1:0:1990:18389
> .locale = (65 00 6E 00 2D 00 55 00 53 00 00 00 ) // e.n.-.U.S...
> }
> .mresource public 'machinelocator.machinelocator.en-US.resources'
> {
> }
> .module machinelocator.resources.dll
> // MVID: {71E99932-5420-4450-890B-ABA1404B3170}
> .imagebase 0x00400000
> .subsystem 0x00000003
> .file alignment 4096
> .corflags 0x00000001
> // Image base: 0x02ca0000
>
>
>
> On 6/13/05, lizet peña <lizet.pena@xxxxxxxxx> wrote:
> > Hello Mark,
> > Thanks for your reply.
> >
> > My main problem seems to be embedding the .resource file I generate
> > from the .resX into the satellite assembly. The ResourceManager class
> > won't get the values inside the XML .resx file so the .resX file needs
> > to be converted into the binary .resources version. (resgen
> > myresources.en-US.resx myresources.en-US.resources). Although the
> > resources embedding into a satellite assembly seems to work fine,
> > here's a copy of my cmd session:
> >
> > C:\Inetpub\wwwroot\machinelocator\bin\en-US>resgen machinelocator..en-USresx
> > Read in 234 resources from 'machinelocator.en-US.resx'
> > Writing resource file... Done.
> >
> > C:\Inetpub\wwwroot\machinelocator\bin\en-US>al.exe /t:lib
> > /embed:machinelocator.
> > en-US.resources /culture:en-US /out:machinelocator.resources.dll
> > Microsoft (R) Assembly Linker version 7.10.3077
> > for Microsoft (R) .NET Framework version 1.1.4322
> > Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
> >
> >
> > C:\Inetpub\wwwroot\machinelocator\bin\en-US>ildasm
> > machinelocator.resources.dll
> >
> > ildasm shows in the manifest that machinelocator.en-US.resources is
> > inside the dll.
> >
> > So far everything seems to be working. Inside my bin directory I have
> > a folder for each culture bin\en-US\ has the
> > machinelocator.resources.dll satellite assembly.
> >
> > On my code there's is something like this:
> > Thread.CurrentThread.CurrentUICulture = New CultureInfo(Me.CurrentCulture)
> > Thread.CurrentThread.CurrentCulture =
> > CultureInfo.CreateSpecificCulture(Me.CurrentCulture)
> > ...
> >
> > Dim a As [Assembly] = [Assembly].Load("machinelocator")
> > Dim rm As ResourceManager = New
> > ResourceManager("machinelocator", a)
> > Dim str As String = rm.GetString("errorMessage",
> > Thread.CurrentThread.CurrentUICulture)
> >
> > However, I put the name of the application on the ResourceManager, and
> > the name of the application is not the same name of the namespace
> > where this assembly runs (IRONSearch), probably that's the source of
> > error. I truly don't know if the name to be put there is the name of
> > the project or the namespace for that particular assembly. I always
> > get the following exception:
> > ex.Message "Could not find any resources appropriate for the
> > specified culture (or the neutral culture) in the given assembly.
> > Make sure "machinelocator.resources" was correctly embedded or linked
> > into assembly "machinelocator".
> > baseName: machinelocator locationInfo: <null> resource file name:
> > machinelocator.resources assembly: machinelocator,
> > Version=1.0.1990.18389, Culture=neutral, PublicKeyToken=null" String
> >
> > Also the Culture info I get is for the neutral Culture when I had set
> > the en-US culture.
> >
> > I tested ResourceManager("IRONSearch", a) as IronSearch is the name of
> > the namespace where the executing assembly is, and I get the same
> > error. The root namespace though is "machinelocator".
> > Sorry that I didn't use generic terms for this, but I guess it's ok.
> > Any idea?
> > Thanks a lot in advance,
> > Lizet
> >
> >
> >
> >
> >
> >
> >
> > On 6/13/05, Mark Kucera <mkucera@xxxxxxxxxxxxxx> wrote:
> > > I've used embedded resources w/ VS.NET 2003 quite successfully. Here are
> > > the steps I've used...
> > >
> > > 1. Create the resource files for each culture i.e.
> > > ResourceFile.resx
> > > ResourceFile.FR.resx
> > > ResourceFile.DE.resx
> > > Etc...
> > >
> > > And add your translated strings to the files.
> > >
> > > 2. Then create a helper class to retrieve the managed content, something
> > > like this:
> > >
> > > public static string GetResourceContent(string name)
> > > {
> > > ResourceManager res = new ResourceManager("Root Namespace Name
> > > Here", Assembly.GetExecutingAssembly());
> > > return res.GetString(name);
> > > }
> > >
> > > 3. I generally put this method in a custom control, similar to a label
> > > that I can put on a page and assign the string name to retrieve from the
> > > resource file...
> > >
> > > namespace MyNameSpace
> > > {
> > > using System;
> > > using System.Web.UI;
> > > using System.Web.UI.WebControls;
> > > using System.Resources;
> > > using System.Reflection;
> > >
> > > /// <summary>
> > > /// Summary description for SiteTextControl.
> > > /// </summary>
> > > public abstract class SiteTextControl : System.Web.UI.UserControl
> > > {
> > > private string _Name;
> > > private string _CssClass;
> > >
> > > private void Page_Load(object sender, System.EventArgs e)
> > > {}
> > >
> > > public string Name
> > > {
> > > get {return _Name;}
> > > set {_Name = value;}
> > > }
> > >
> > > public string CssClass
> > > {
> > > get
> > > {
> > > if (_CssClass == null || _CssClass.Length
> > > == 0)
> > > _CssClass = "font-md";
> > >
> > > return _CssClass;
> > > }
> > > set {_CssClass = value;}
> > > }
> > >
> > > protected sealed override void CreateChildControls()
> > > {
> > > ResourceManager res = new
> > > ResourceManager("Root Namespace Name Here",
> > > Assembly.GetExecutingAssembly());
> > > string _Text = "";
> > > if (_CssClass != null && _CssClass.Length != 0)
> > > _Text = "<span class=\"" + _CssClass +
> > > "\">" + res.GetString(_Name) + "</span>";
> > > else
> > > _Text = res.GetString(_Name);
> > >
> > > LiteralControl lit = new
> > > LiteralControl(_Text);
> > > Controls.Add(lit);
> > > lit.Dispose();
> > > }
> > >
> > > public static string GetResourceContent(string name)
> > > {
> > > ResourceManager res = new
> > > ResourceManager("Root Namespace Name Here",
> > > Assembly.GetExecutingAssembly());
> > > return res.GetString(name);
> > > }
> > >
> > > #region Web Form Designer generated code
> > > protected sealed override void OnInit(EventArgs e)
> > > {
> > > //
> > > // CODEGEN: This call is required by the ASP.NET
> > > Web Form Designer.
> > > //
> > > InitializeComponent();
> > > base.OnInit(e);
> > > }
> > >
> > > /// Required method for Designer support - do
> > > not modify
> > > /// the contents of this method with the code
> > > editor.
> > > /// </summary>
> > > private void InitializeComponent()
> > > {
> > > this.Load += new
> > > System.EventHandler(this.Page_Load);
> > > }
> > > #endregion
> > > }
> > > }
> > >
> > >
> > > 4. Then I add the control to a page (or other control) where I want to
> > > use managed content
> > > <%@Register tagprefix="MyTagPrefix" Tagname="SiteTextControl"
> > > src="SiteTextControl.ascx" %>
> > >
> > > <p> <MyTagPrefix:SiteTextControl id="Sitetextcontrol1" runat="Server"
> > > name="Name of string to lookup" /></p>
> > >
> > > As long as you have set the
> > > System.Globalization.CultureInfo.CurrentCulture to the correct target
> > > culture, you can rely on the resource manager to read the string from the
> > > correct resource file. It should fall back on the English version if it
> > > can't find the string in the target culture's resource file.
> > >
> > > I think the most tricky thing I encountered when I was setting this up,
> > > was making sure the namespace that I passed in to the ResourceManager
> > > constructor was correct, but you should be able to use Reflector, or
> > > ILDasm to make sure your resource files are being included in the
> > > assembly, and to check their names...
> > >
> > > Good Luck
> > > MK
> > >
> > >
> > >
> > > Mark Kucera
> > > mkucera@xxxxxxxxxxxxxx
> > >
> > >
> > > -----Original Message-----
> > > From: Discussion of building .NET applications targeted for the Web
> > > [mailto:DOTNET-WEB@xxxxxxxxxxxxxxxxxxx] On Behalf Of lizet peña
> > > Sent: Monday, June 13, 2005 10:56 AM
> > > To: DOTNET-WEB@xxxxxxxxxxxxxxxxxxx
> > > Subject: [DOTNET-WEB] embedding resources for globalization (complete
> > > frustration)
> > >
> > > Well, our team decided to go back to VS 2003 instead of deploying the
> > > project on 2005, the reasons are not part of this email.
> > > Our current problem is with 1.1 Framework. We have a .resX file for
> > > each web form on the project and would like to access each resource in
> > > it. The ResourceManager class would only work with .resources files
> > > and in order to access them, these files should be embedded into
> > > satellite assemblies.
> > > We followed the steps in
> > > http://www.codeproject.com/dotnet/Localization.asp
> > >
> > > Al.exe
> > > /t:lib
> > > /embed: MyApplication.en-GB.resources,
> > > /culture:en-GB
> > > /out:MyApplication.resources.dll
> > >
> > > and created a MyApplication.resources.dll for each culture. We
> > > previously converted the .resX files into .resources with resgen.exe.
> > > Resgen MyApplication.en-GB.resX
> > >
> > > In order to load the specific resource:
> > >
> > > Dim a As [Assembly] = [Assembly].Load("MyApplication")
> > > Dim rm As ResourceManager = New
> > > ResourceManager("searchUI", a)
> > > Dim str As String = rm.GetString("errorMessage",
> > > Thread.CurrentThread.CurrentUICulture)
> > >
> > > The assembly loads fine and the resource manager is instantiated
> > > correctly, however when we try to get the string with the particular
> > > resource, there's is an exception saying the resource cannot be
> > > located, to make sure the .resource file is embedded in the satellite
> > > assembly.
> > > Any ideas of where to start troubleshooting the error are more than
> > > welcome, I have generated the satellite assemblies three times now and
> > > honestly don't know why the resources aren't loaded at all.
> > > Thanks in advance,
> > > Lizet
> > >
> > > ===================================
> > > This list is hosted by DevelopMentor(r) http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > > http://discuss.develop.com
> > >
> > > ===================================
> > > This list is hosted by DevelopMentor(r) http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > > http://discuss.develop.com
> > >
> >
>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise