无法加载文件或程序集 'System.Drawing' 或其依赖项之一

Could not load file or assembly 'System.Drawing' or one of its dependencies

我从昨天开始就收到这个错误,在 'searching trying and crying' 我最后在这里问了这个问题。

An unhandled exception of type 'System.InvalidOperationException' occurred in 'project.exe'

The error is: 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.

此项目设置为使用 3.5-Framework。当加载表单时,当我的资源包含图像或其中使用图形的任何内容时,就会发生错误。 (删除 form-icon 和 button-images 'solves' 的问题)。 我已经尝试了以下方法:

  1. 对项目进行了 'Clean' & 'Rebuild'
  2. 删除了 System.Drawing 引用,并重新添加。
  3. 将 *.resx 中资源的访问修饰符设置为 'no code generation'。
  4. 正在搜索 *resx 文件中的“4.0.0.0”以替换为“2.0.0.0”,但“4.0.0.0”未在任何地方列出。

过去有人提出过这个问题,但似乎没有任何建议可以解决我的问题?

感谢阅读。谢谢你的时间。 伯特

我建议您尝试以下方法

  1. 检查 ildasm 是否有任何 DLL 仍然引用 System.Drawing DLL

  2. 的 v4.0
  3. 在您的 web.config 中添加绑定重定向,以便正确进行版本重定向。

HTH

当我试图记住在这个错误开始发生之前发生了什么变化时,我记得设置了一个我设置的系统变量:

正在尝试修复错误

MSBUILD:错误 MSB4017:无法 运行 "GenerateResource" 任务,因为 MSBuild 无法使用 运行time [=32] 创建或连接到任务主机=] 和体系结构 "x86".

  1. 关闭Visual studio
  2. 删除了所述系统变量
  3. 重建解决方案(甚至不编辑任何 icons/images)

现在可以用了……奇怪!