简体   繁体   English

Mac中的MonoDevelop,ResourceManager无法从资源文件读取值

[英]MonoDevelop in mac, ResourceManager can not read value from resource file

We meet one issue for loading Mac resource with Xamarin. 我们遇到了一个使用Xamarin加载Mac资源的问题。 We have one resource file named Resource1.resx. 我们有一个名为Resource1.resx的资源文件。 It failed when loading one string from this resource file with below code. 使用以下代码从此资源文件加载一个字符串时,它失败。 Please refer attachment sample to create this issue. 请参考附件样本来创建此问题。 Could you please give some advice to load resource? 您能否提供一些加载资源的建议?

If you need any more information, please let me know that. 如果您需要更多信息,请告诉我。 Please check the codes(in MainWindows.cs) as follow: 请检查代码(在MainWindows.cs中),如下所示:

partial void loadResourceButtonClicked(MonoMac.Foundation.NSObject sender){
    try{
        var b = Resources1.ResourceManager;
        var name = b.GetString("Name1");
        resultLabel.StringValue = name;
    }
    catch {
        resultLabel.StringValue = "Resource load failed.";
    }
}

PS.We have attached the test project , please have a check. PS。我们已经附上了测试项目 ,请检查一下。

Thanks. 谢谢。

Your 'hidden' exception: 您的“隐藏”例外:

Could not find any resources appropriate for the specified culture or the neutral culture. 找不到适合于指定区域性或中性区域性的任何资源。 Make sure "MacResourceTest.Resources1.resources" was correctly embedded or linked into assembly "MacResourceTest" at compile time, or that all the satellite assemblies required are loadable and fully signed. 确保在编译时已将“ MacResourceTest.Resources1.resources”正确嵌入或链接到程序集“ MacResourceTest”中,或者确保所需的所有附属程序集均已加载并完全签名。

The key phase in that exception message is ' Make sure XXXX was correctly embedded or linked into assembly '. 该异常消息中的关键阶段是“ 确保XXXX已正确嵌入或链接到程序集中 ”。

A quick look at your project and the .resx file is flagged incorrectly as a Build Action of BundleResource . 快速浏览您的项目, .resx文件被错误地标记为BundleResourceBuild Action OSX/iOS BundleResource's are typically used for binary, xml, text, etc.. but NOT .resx files as they originate via the System.Resources.ResourceManager and need to be added to the CIL assembly in a specific way (mainly due to culture localization). OSX / iOS BundleResource通常用于二进制,xml,文本等。但不是.resx文件,因为它们是通过System.Resources.ResourceManager并且需要以特定方式添加到CIL程序集中(主要是由于区域性)本土化)。

1) Flag .resx files as a Build Action of EmbeddedResource 1)将.resx文件标记为EmbeddedResourceBuild Action

2) If your going to 'hide' exceptions and provide a 'user friendly' message, include the actual exception messages in Console debugging messaging, logging, somewhere, etc... 2)如果您要“隐藏”异常并提供“用户友好”消息,请在控制台调试消息传递,日志记录,某处等中包含实际的异常消息...

3) In posting questions to StackOverflow, please post the actual exception message / call stack. 3)在向StackOverflow发布问题时,请发布实际的异常消息/调用堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM