我创建了一个程序集,后来重命名了它。
然后我开始在调用时遇到运行时错误:
toolsMenuName = resourceManager.GetString(resourceName);
resourceName
变量在运行时是 "enTools"。
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.
代码:
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 属性设置为“嵌入式资源”
关于c# - 找不到适合指定文化或中性文化的任何资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4690713/