无法在代码中加载 resx 文件
我有一个 C# 库 (MyApp.ServiceLayer),我想从另一个库 (MyApp.Common) 访问通用 resx (/Resources/global.en-GB.resx) 文件。我已添加从 ServiceLayer 到 Common 的引用。
在 ServiceLayer 的 /bin/Debug 文件夹中,我有(除其他外):
- MyApp.Common.dll
- en-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")));
为什么我达不到呢?
I have a C# library (MyApp.ServiceLayer) and I want to access a common resx (/Resources/global.en-GB.resx) file from another library (MyApp.Common). I've added a reference from ServiceLayer to Common.
In the /bin/Debug folder of ServiceLayer I have (amongst others):
- MyApp.Common.dll
- en-gb/MyApp.Common.resources.dll.
- /Resources/global.en-GB.resx
Reflector tells me that MyApp.Common.resources.dll has a Resources folder and a resource file: MyApp.Common.Resources.global.en-GB.resources
This code returns "could not load assembly" error.
ResourceManager resource = new ResourceManager("resources.global", Assembly.Load(new AssemblyName("MyApp.Common.resource")));
Why can't I get to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当资源文件已加载到当前 AppDomain 中时,AssemblyName 加载才有效。
使用方法 LoadFrom() 而不是 Load() 从文件加载程序集:
The loading by AssemblyName only works if the resource file has been loaded into the current AppDomain.
Use the method LoadFrom() instead of Load() to load the assembly from a file: