相关疑难解决方法(0)

"无法加载.Net 2.0,VS2010和Windows 8上的文件或程序集System.Drawing或其中一个依赖项"错误

我在Windows窗体应用程序项目上收到FileNotFoundException,并显示以下消息:

Could not load file or assembly 'System.Drawing, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 
The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)

要复制问题:

  • 选择New,Project,选择.Net Framework 2.0作为目标,并选择Windows Forms Application作为项目类型.
  • 在默认情况下创建的表单的属性上,选择Icon属性的值.任何.ico文件都可以.这将把文件嵌入resx文件.
  • 编译并运行应用程序.

当我这样做时,程序在行this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));上停止,但有以下异常:

System.IO.FileNotFoundException was unhandled
  Message=Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  Source=mscorlib
  FileName=System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Run Code Online (Sandbox Code Playgroud)

我在最近安装在Windows 8开发人员预览版上的Visual Studio 2010 SP1上得到了这个.如果我将项目属性更改为目标.Net Framework 4,则错误消失.

在Form1.resx文件中,我可以看到System.Drawing程序集的版本明确声明为2.0:

<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" …
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-2010 .net-2.0 windows-8

16
推荐指数
3
解决办法
4万
查看次数

标签 统计

.net-2.0 ×1

c# ×1

visual-studio-2010 ×1

windows-8 ×1