"无法加载文件或程序System.Drawing中或其依赖&QUOT之一;错误的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

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

问题描述

我得到一个FileNotFoundException异常在Windows窗体应用程序项目,并显示以下消息:


 无法加载文件或程序'System.Drawing中,版本= 4.0.0.0,
文化=中性公钥= b03f5f7f11d50a3a'或它的一个依赖。
该系统找不到指定的文件。


要复制的问题:


  • 选择新建,项目,选择.Net框架2.0作为目标,并选择Windows窗体作为项目类型的应用。

  • 在默认创建的窗体的属性,选择图标属性的值。任何.ico文件就行了。这将嵌入的RESX文件的文件。

  • 编译并运行应用程序。

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

  System.IO.FileNotFoundException了未处理
  消息=无法加载文件或程序集System.Drawing中,版本= 4.0.0.0,文化=中性公钥= b03f5f7f11d50a3a'或它的一个依赖。该系统找不到指定的文件。
  来源= mscorlib程序
  文件名= System.Drawing中,版本= 4.0.0.0,文化=中性公钥= b03f5f7f11d50a3a

我得到这个上的Visual Studio 2010 SP1,最近安装在Windows 8开发preVIEW。如果我更改项目性质为目标.Net框架4,错误消失。

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

 <装配别名=System.Drawing中NAME =System.Drawing中,版本= 2.0.0.0,文化=中性公钥= b03f5f7f11d50a3a/>

任何想法?


解决方案

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

从公共开放Designer中RESX文件和设置accessmodifier没有code产生。

编辑:有一个变通方法,但很烦人,虽然


  1. 在设计器中打开表,并做出必要的改变GUI。关闭设计师和保存

  2. 编译项目,并收到RESX编译错误(仅适用于图像列表的形式应该有这个问题)

  3. 双击RESX编译错误打开RESX文件。

  4. 滚动到的ImageStream之上。

  5. 编辑的图像流的第一行:
    AAEAAAD ///// AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w

    AAEAAAD ///// AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w

  6. 保存并关闭文件RESX并重新编译。

**注意:唯一的区别是在结束j00LjAuMC4w为j0yLjAuMC4w人物
这需要做在Designer模式打开窗体每次。

微软表示,他们将修复它在未来的版本VS ...

来源:<一个href=\"http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020\" rel=\"nofollow\">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

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

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