Winform映像(ResourceManager)在Windows 10上不可见

时间:2016-05-11 05:41:05

标签: c# winforms windows-10 resourcemanager

我有一个Windows窗体应用程序在Windows 7上运行正常,但在Windows 10中打开时,使用 ResourceManager 的图像文件不会显示。应用程序正在使用.Net 3.5框架。以下是一些代码:

static readonly System.Resources.ResourceManager rm = new System.Resources.ResourceManager("ImageResources", Assembly.GetExecutingAssembly());

rm.GetObject("ImageName");

以下是错误:

  

无法找到适合指定文化的任何资源或   中性文化。确保已正确嵌入或链接到   汇编在编译时,或所有附属程序集   必需的是可加载和完全签名。   System.Resources.MissingManifestResourceException:

是否由于某种不兼容性或Windows 10以某种方式限制ResourceManager类使用所有这些图像?

2 个答案:

答案 0 :(得分:1)

Try to check value of Environment.Version (with some MessageBox for example) on the target machine. If you get 4.0 then you need to change configuration file as was proposed by Dr. Stich. If you don't have configuration file then create it like described there: How to: Add an Application Configuration File to a C# Project

And change it content to something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
  <supportedRuntime version="v2.0.50727" />
</startup>
</configuration>

Runtime version you can get on supportedRuntime Element page

答案 1 :(得分:0)

最终通过在CultureInfo.CurrentCulture方法参数中添加rm.GetObject来解决此问题,即

rm.GetObject("ImageName", CultureInfo.CurrentCulture);