Visual Studio 遇到“System.BadImageFormatException”异常

By | 2019-12-16

在调试Winform程序时遇到如下错误:

“System.BadImageFormatException”类型的未经处理的异常在 未知模块。 中发生
未能加载文件或程序集“OpenPCINFO.exe”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。 出现了

System.BadImageFormatException

产生的原因是将.NETFramework版本从2.0改为了4.5

解决办法只要将app.config中的v2.0删除即可

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <!--<supportedRuntime version="v2.0.50727"/>-->
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
</configuration>

再次运行已经不会弹出 System.BadImageFormatException 错误了

发表评论

邮箱地址不会被公开。 必填项已用*标注