ResourceManager 无法通过指定键获取值
我正在尝试从 Resource
获取一些值。但每次它都会给我以下错误:
[MissingManifestResource_NoNeutralAsm] 参数:FreakyBoss.Client.Resources.Language.resources,FreakyBoss.Client 调试资源字符串不可用。通常,键和参数提供了足够的信息来诊断问题。请参阅 http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.60401.00&File=mscorlib.dll&Key=MissingManifestResource_NoNeutralAsm
我的代码是这样的:
private readonly ResourceManager _resourceManager;
public TranslationProvider() {
_resourceManager = new ResourceManager("FreakyBoss.Client.Resources.Language", Assembly.GetExecutingAssembly());
}
public string GetResourceValue(string key) {
return _resourceManager.GetString(key);
}
我的解决方案结构:
我不知道出了什么问题。我有两个资源文件,如上图所示。 我认为 ResourceManager
中构造函数的 BaseName
参数存在问题。 但我不知道应该如何解决这个问题。
任何建议都会有所帮助。
I'm trying to get some values from Resource
. But each time it gives me the following error :
[MissingManifestResource_NoNeutralAsm]
Arguments: FreakyBoss.Client.Resources.Language.resources,FreakyBoss.Client
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.60401.00&File=mscorlib.dll&Key=MissingManifestResource_NoNeutralAsm
My code is something like this :
private readonly ResourceManager _resourceManager;
public TranslationProvider() {
_resourceManager = new ResourceManager("FreakyBoss.Client.Resources.Language", Assembly.GetExecutingAssembly());
}
public string GetResourceValue(string key) {
return _resourceManager.GetString(key);
}
My solution structure :
I don't know what's the problem. I've two resource files as you can see in the image above.
I think there is a problem with BaseName
argument of constructor in ResourceManager
.
But I don't know how should I fix this problem.
Any advice will be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的理解,您需要有一个默认资源,然后添加特定于语言的资源。因此,在您的情况下,您将拥有(假设 en 是默认值):
资源文件已经生成了所有代码,因此您不必编写代码来生成资源管理器。只需访问 Language.ResourceManager 属性即可。
From my understanding you need to have a default resource and then add in the language specific resources. So in your case you would have (assuming en is default):
The resource file already has all the code generated so you shouldn't have to write the code to generate the resource manager. Just access the Language.ResourceManager property.