ASP.NET 应用程序未拾取卫星程序集

发布于 2024-10-14 23:57:16 字数 523 浏览 6 评论 0原文

我有一个名为“TestResourceApp”的网络项目,其 Labels.resx 位于 App_GlobalResources 文件夹中。我想通过创建附属程序集来添加另一种语言。

以下是我创建卫星程序集所采取的步骤。始终显示默认文本。我做错了什么?

1) 在不同的文件夹中创建 Labels.fr.resx。

2) 生成资源文件:

Resgen Labels.fr.resx TestResourceApp.App_GlobalResources.Labels.fr.resources

3) 生成卫星程序集:

AL /t:lib /embed:TestResourceApp.App_GlobalResources.Labels.fr.resources /out:french.dll /c:fr

4) 将 french.dll 复制到 TestResourceApp/bin/fr

我已在 web.config 中将 uiculture 设置为 auto,并且更改了浏览器上的语言。

I have a web project called "TestResourceApp" with Labels.resx in App_GlobalResources folder. I want to add another language by creating a satellite assembly.

Here are the steps I took to create the satellite assembly. The default text always get displayed. What did I do wrong ?

1) Create Labels.fr.resx in a different folder.

2) Generate resource file:

Resgen Labels.fr.resx TestResourceApp.App_GlobalResources.Labels.fr.resources

3) Generate satellite assembly:

AL /t:lib /embed:TestResourceApp.App_GlobalResources.Labels.fr.resources /out:french.dll /c:fr

4) Copy french.dll to TestResourceApp/bin/fr

I have uiculture set to auto in web.config and I have change the language on the browser.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆光下的微笑 2024-10-21 23:57:16

我能够使用此页面来解决我遇到的一些卫星组装问题。我会再添加一些内容来检查。

反编译“中性”程序集并查看它是如何组合在一起的会很有帮助。像 ILDASM.exe 这样的工具有助于实现此目的。反编译后,查看文本输出中的“.mresource”,您应该会看到一个带有您的命名的文本。例如,如果将资源添加到 Visual Studio 项目,它们将被命名为 MyAssemblyName +“.Properties.Resources”+一种语言(如果有)+“.resources”示例:

MyAssembly.Properties.Resources.resources(中性语言)
MyAssembly.Properties.Resources.en-US.resources(英语(美国))

在我的例子中,我将文件命名正确,并位于相应的文件夹中(例如 Bin\en-US)。我能够通过使用 ProcMon.exe(由 SysInternals 人员)验证这一点,并且可以看到工作进程在我的 DLL 文件中查找和读取(而不是仅仅说“PATH NOT FOUND”)。但是,它没有按照预期的名称找到资源。这时,一些反汇编有助于弄清命名问题的根源。

因此,请使用 ProcMon.exe 来缩小您可能遇到的问题类型。希望这对某人有帮助。

I was able to use this page to solve some satellite assembly issues I was having. I'll throw in a few more things to check.

It's helpful to decompile the "neutral" assembly and see how it's put together. A tool like ILDASM.exe is helpful for this purpose. Once you get it decompiled, look through the text output for ".mresource", and you should see one with your naming. For example, if you add a resource to a Visual Studio project, they're named MyAssemblyName + ".Properties.Resources" + a language (if any) + ".resources" Examples:

MyAssembly.Properties.Resources.resources (neutral language)
MyAssembly.Properties.Resources.en-US.resources (English (US))

In my case, I had the file named properly, and in the appropriate folder (such as Bin\en-US). I was able to verify that much by using ProcMon.exe (by the SysInternals guys) and could see the worker process finding and reading in my DLL file (instead of just saying "PATH NOT FOUND"). However, it was not finding the resource by the name that it expected it to. That's when some disassembly helped to get to the bottom of the naming problem.

So, use ProcMon.exe to narrow down the kind of problem you might have. Hopefully that's helpful to someone.

浅忆 2024-10-21 23:57:16

这很复杂,但对于遇到此问题的人来说,这里有一些提示:

  • 尝试将 resx 包含在 Web 项目中,然后让 VS 为您完成这项工作。
  • 反射器是你的朋友。比较您创建的附属程序集和 VS 创建的附属程序集。
  • 如果您的 Web 应用程序面向 ASP.NET 2.0,则应使用 .net 2.0 附带的 Resgex 和 AL。在 Reflector 中打开程序集并检查“引用”。它应该引用 mscorlib 版本 2.0。
  • 如果使用 Web 部署项目部署 Web 应用程序,请确保附属程序集中资源的命名空间正确。再次与 VS 创建的内容进行比较。就我而言,我使用了错误的工具来生成 Designer.cs 文件,因为我希望可以从不同的程序集中访问它们。确保您使用的是 GlobalResourceProxyGenerator。否则,命名空间将不匹配,部署代码将无法找到您的资源。 Designer.cs 中的命名空间应该只是“Resources”,而不是“XXXX.App_GlobalResources”

It's complicated but here are a few tips for those who run into this problem:

  • Try to include the resx in the web project and let VS do the job for you.
  • Reflector is your friend. Compare satellite assemblies you created and those created by VS.
  • If you web app is targetting ASP.NET 2.0, you should use Resgex and AL that come with .net 2.0. Open the assemblies in Reflector and check the "references". It should reference mscorlib version 2.0.
  • If you deploy your web app using web deployment project, make sure the namespace for the resources in your satellite assemblies is correct. Again, compare with what VS creates. In my case, I used the wrong tool to generate the designer.cs file because I wanted them to be accessible from a different assembly. Make sure you are using GlobalResourceProxyGenerator. Otherwise, the namespaces won't match and the deployment code will not be able to find your resource. The namespace in the designer.cs should simply be "Resources", not "XXXX.App_GlobalResources"
一张白纸 2024-10-21 23:57:16

您是否已在全球化中将 enableClientBasedCulture 设置为 true

Did you have set enableClientBasedCulture to true in globalization ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文