我的应用程序的目的是从程序集中选取一些本地化字符串。规范的一部分是:
- 该程序集将由用户在运行时选择
- 该程序集是私有的,即未向 GAC 注册
我想出的代码是:
Assembly resAssembly = Assembly.LoadFile(@"X:\PathToApp\Assembly.Name.dll");
CultureInfo ci = new CultureInfo("es-MX");
Assembly satAssembly = resAssembly.GetSatelliteAssembly(ci);
最后一行引发了异常:
无法加载文件或程序集“Assembly.Name.resources”或其依赖项之一。系统找不到指定的文件。
我通过将包含附属程序集的文件夹复制到应用程序根目录来克服了该异常。
我不喜欢这种方法。还有其他想法吗?
预先非常感谢
The purpose of my application is to pick some localized strings from an assembly. Part of the specification is:
- The assembly is to be selected by the user at run-time
- The assembly is private one, i.e. not registered with GAC
The code I came up with is:
Assembly resAssembly = Assembly.LoadFile(@"X:\PathToApp\Assembly.Name.dll");
CultureInfo ci = new CultureInfo("es-MX");
Assembly satAssembly = resAssembly.GetSatelliteAssembly(ci);
The last line threw an exception:
Could not load file or assembly "Assembly.Name.resources" or one of its dependencies. The system can not find the file specified.
I have overcome the exception by copying the folders that contain the satellite assemblies to the application root.
I do not like this approach. Any alternative ideas?
Many thanks in advance
发布评论
评论(1)
Assembly.LoadFile
方法不使用绑定上下文,因此不会在其目录中自动找到其依赖项。您可以改用
Assembly.LoadFrom
。您可以阅读 Suzanne Cook 关于这两种方法之间差异的文章,以获取更多信息 (LoadFile 与 LoadFrom)。
The
Assembly.LoadFile
method doesn't use a binding context, so its dependencies aren't automatically found in its directory.You can instead use
Assembly.LoadFrom
.You can read Suzanne Cook's post on the differences between these two methods to obtain further information (LoadFile vs. LoadFrom).