gpt4 book ai didi

c# - .Net 2.0、VS2010 和 Windows 8 上的 "Could not load file or assembly System.Drawing or one of its dependencies"错误

转载 作者:可可西里 更新时间:2023-11-01 03:08:43 25 4
gpt4 key购买 nike

我在 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.

重现问题:

  • 选择新建、项目,选择 .Net Framework 2.0 作为目标并选择 Windows Forms 应用程序作为项目类型。
  • 在默认创建的表单的属性中,为 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

我在最近安装在 Windows 8 Developer Preview 上的 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" />

有什么想法吗?

最佳答案

这是一个错误。我也看到了。发生这种情况是因为您的 .resx 文件指向 System.Drawing 的 4.0.0.0 版本,其中一个不存在。为了克服这个问题,我通常在记事本中编辑 .resx 以将 4.0.0.0 更改为 2.0.0.0。该错误是按照您概述的确切步骤引入的。

关于c# - .Net 2.0、VS2010 和 Windows 8 上的 "Could not load file or assembly System.Drawing or one of its dependencies"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9190885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com