我在Windows窗体应用程序项目上收到FileNotFoundException,并显示以下消息:
Run Code Online (Sandbox Code Playgroud)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.
要复制问题:
当我这样做时,程序在行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)