找不到适合指定文化或中性文化的资源 [英] Could not find any resources appropriate for the specified culture or the neutral culture

查看:171
本文介绍了找不到适合指定文化或中性文化的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



然后,在调用时,我开始收到运行时错误:

  toolsMenuName = resourceManager.GetString(resourceName); 

resourceName 变量为 entools


找不到指定文化
的资源
或中性文化。确保
Jfc.TFSAddIn.CommandBar.resources
已正确嵌入或链接到
程序集Jfc.TFSAddIn,在编译
时,或所有卫星
程序集可以加载,
完全签名。


代码:

  string resourceName; 
ResourceManager resourceManager = new ResourceManager(Jfc.TFSAddIn.CommandBar,Assembly.GetExecutingAssembly());

CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);

if(cultureInfo.TwoLetterISOLanguageName ==zh)
{
CultureInfo parentCultureInfo = cultureInfo.Parent;
resourceName = String.Concat(parentCultureInfo.Name,Tools);
}
else
{
resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName,Tools);
}

toolsMenuName = resourceManager.GetString(resourceName); // EXCEPTION IS HERE

我可以看到项目中包含的CommandBar.resx文件,我可以打开它可以看到enTools字符串。似乎这两个资源都不包含在程序集中,或者包含资源,但.NET无法解析名称。

解决方案

我觉得更简单解决方案是为每种语言创建单独的资源文件。



就这种情况而言,检查包含资源的程序集是否将默认命名空间设置为相同的文本(项目 - >属性 - >默认命名空间;在VS中)



检查resx文件是否具有将BuildAction设置为Embedded resource的属性


I have created an assembly and later renamed it.

Then I started getting runtime errors when calling:

toolsMenuName = resourceManager.GetString(resourceName);

The resourceName variable is "enTools" at runtime.

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Jfc.TFSAddIn.CommandBar.resources" was correctly embedded or linked into assembly "Jfc.TFSAddIn" at compile time, or that all the satellite assemblies required are loadable and fully signed.

The code:

string resourceName;
ResourceManager resourceManager = new ResourceManager("Jfc.TFSAddIn.CommandBar", Assembly.GetExecutingAssembly());

CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);

if(cultureInfo.TwoLetterISOLanguageName == "zh")
{
     CultureInfo parentCultureInfo = cultureInfo.Parent;
     resourceName = String.Concat(parentCultureInfo.Name, "Tools");
}
else
{
     resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
}

toolsMenuName = resourceManager.GetString(resourceName); // EXCEPTION IS HERE

I can see the file CommandBar.resx included in the project, I can open it and can see the "enTools" string there. It seems that either resources are not included into assembly or resource are included but .NET cannot resolve the name.

解决方案

I think simpler solution would be to create separate resources file for each language.

As far as this case is concerned check if the assembly containing resources has the default namespace set to the same text (Project->Properties->Default namespace; in VS)

Check as well if the resx file has a property BuildAction set to "Embedded resource"

这篇关于找不到适合指定文化或中性文化的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆