无法在代码中加载resx文件

时间:2010-12-24 23:53:13

标签: c# .net localization resx

我有一个C#库(MyApp.ServiceLayer),我想从另一个库(MyApp.Common)访问一个公共resx(/Resources/global.en-GB.resx)文件。我已经将ServiceLayer的引用添加到Common。

在ServiceLayer的/ bin / Debug文件夹中,我(其中包括):

  • MyApp.Common.dll
  • 烯GB / MyApp.Common.resources.dll。
  • /Resources/global.en-GB.resx

Reflector告诉我MyApp.Common.resources.dll有一个Resources文件夹和一个资源文件:MyApp.Common.Resources.global.en-GB.resources

此代码返回“无法加载程序集”错误。

ResourceManager resource = new ResourceManager("resources.global", Assembly.Load(new AssemblyName("MyApp.Common.resource")));

为什么我不能接受它?

1 个答案:

答案 0 :(得分:0)

仅当资源文件已加载到当前AppDomain中时,AssemblyName的加载才有效。

使用方法 LoadFrom()而不是加载() 从文件加载程序集:

ResourceManager resource = new ResourceManager("resources.global", Assembly.LoadFrom(@"C:\full\path\of\the\assembly\MyApp.Common.resources.dll"));
相关问题