BadImageFormatException - 是否有可能指定哪个.NET版本用于运行可执行文件? [英] BadImageFormatException - Is it possible to specify which .NET version is used to run an executable?

查看:323
本文介绍了BadImageFormatException - 是否有可能指定哪个.NET版本用于运行可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个.NET 2.0可执行.com扩展名从一个命令行收到以下错误:

I'm running a .NET 2.0 executable with a .com extension from a command line and receiving the following error:

System.BadImageFormatException : The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)

我是pretty的确保它试图加载从.NET 2.0全局程序集缓存的DLL。

I'm pretty sure it's trying to load a DLL from the .NET 2.0 Global Assembly Cache.

我只得到与.NET 4.0 / Visual Studio 2010的机器上安装这个错误,所以我使用了错误的.NET Framework版本运行假设它。 关于如何确认这个假设任何想法?

I only get this error on machines with .net 4.0 / visual studio 2010 installed, so I'm assuming its using the wrong .net framework version to run. Any ideas on how to confirm this assumption?

或者是有办法规定程序使用.NET 2运行时,而不是.NET 4运行.com文件?

or is there a way to specify the program to use .net 2 runtime instead of .net 4 to run the .com file?

推荐答案

如果只有.NET 4.0框架安装并要运行的应用程序构建/使用.NET 2.0,则需要通知.NET 4.0框架该应用程序需要.NET 2.0运行时。这是通过使用配置文件以下条目。

If only the .NET 4.0 Framework is installed and you want to run an application build for/with .NET 2.0, you need to inform the .NET 4.0 Framework that the application requires the .NET 2.0 Runtime. That is done using a configuration file with the following entries.

必要的属性设置为 useLegacyV2RuntimeActivati​​onPolicy

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v2.0.50727"/>
  <supportedRuntime version="v4.0.30319"/>
 </startup>
</configuration>

这篇关于BadImageFormatException - 是否有可能指定哪个.NET版本用于运行可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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