c# - 找不到适合指定文化或中性文化的任何资源

标签 c# .net exception-handling localization resources

我创建了一个程序集,后来重命名了它。

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

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/

相关文章:

.net - Dotnet 核心应用程序的 Clickonce 部署等效项

c# - 如何将类元数据转换为 JSON 字符串

Java 多捕获/重新抛出

c# - 在开发模块化应用程序时使用快速失败的方法

java - 如何将 Exceptional 对象转换为 Java checked Exception 之一?

c# - 为什么日期字段存储的值与 null 不同

c# - 初学者如何在 Linux 中开始使用 Mono?

c# - 如何检测二值图像RGB中的圆?

c# - 将自定义方法作为线程运行

c# - 如何从 WinUI 3 C# 应用程序托管 PowerShell 5