“无法加载文件或程序集 System.Drawing 或其依赖项之一".Net 2.0、VS2010 和 Windows 8 上的错误 [英] "Could not load file or assembly System.Drawing or one of its dependencies" error on .Net 2.0, VS2010 and Windows 8

查看:30
本文介绍了“无法加载文件或程序集 System.Drawing 或其依赖项之一".Net 2.0、VS2010 和 Windows 8 上的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<块引用>

无法加载文件或程序集System.Drawing, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一.该系统找不到指定的文件.

重现问题:

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

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

System.IO.FileNotFoundException 未处理Message=无法加载文件或程序集System.Drawing,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"或其依赖项之一.该系统找不到指定的文件.源=mscorlib文件名=System.Drawing,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a

我在 Visual Studio 2010 SP1 上得到了这个,最近安装在 Windows 8 Developer Preview 上.如果我将项目属性更改为面向 .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"/>

有什么想法吗?

解决方案

我找到了一个可能的解决方案,请试试这个:

在设计器中打开 resx 文件并将 accessmodifier 从 public 设置为 no code generation.

有一个解决方法,但很烦人.

  1. 在 Designer 中打开 Form 并进行所需的 GUI 更改.关闭设计器并保存
  2. 编译项​​目并收到RESX编译错误(只有带有Imagelist的表单才会有这个问题)
  3. 双击 resx 编译错误以打开 resx 文件.
  4. 滚动到图像流的顶部.
  5. 编辑图像流的第一行:AAEAAAD////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w到AAEAAAD////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
  6. 关闭并保存 resx 文件并重新编译.

**注意:唯一的区别是j00LjAuMC4w"到j0yLjAuMC4w"结尾的字符每次在设计器模式下打开表单时都需要执行此操作.

微软表示他们将在下一个 VS 版本中修复它...

来源:http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020

I am getting a FileNotFoundException on a Windows Forms Application project, with the following 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.

To replicate the problem:

  • Select New, Project, choose .Net Framework 2.0 as the target and pick Windows Forms Application as the project type.
  • On the properties of the form created by default, select a value for the Icon property. Any .ico file will do. This will embed the file on the resx file.
  • Compile and run the application.

When I do this, the program stops on the line this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); with the following exception:

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

I’m getting this on Visual Studio 2010 SP1, recently installed on Windows 8 Developer Preview. If I change the project properties to target .Net Framework 4, the error goes away.

On the Form1.resx file, I can see that the version of the System.Drawing assembly is explicitly stated as 2.0:

<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Any ideas?

解决方案

I've found a possible solution, please try this:

Open the resx File in the Designer and set the accessmodifier from public to no code generation.

Edit: there's a workaround, but very annoying though.

  1. Open Form in Designer and make needed GUI changes. Close designer and save
  2. Compile project and receive RESX compile error (only forms with Imagelist should have this problem)
  3. Double-click resx compile error to open resx file.
  4. Scroll to top of imagestream.
  5. Edit the top line of the Image stream: AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w TO AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
  6. Close and save resx file and recompile.

**NOTE: the only difference are the characters at end "j00LjAuMC4w' to "j0yLjAuMC4w" This needs to be done EVERY TIME you open the form in Designer mode.

Microsoft says they are going to fix it in the next VS version...

Source: http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020

这篇关于“无法加载文件或程序集 System.Drawing 或其依赖项之一".Net 2.0、VS2010 和 Windows 8 上的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆