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)
I'm pretty sure it's trying to load a DLL from the .NET 2.0 Global Assembly Cache.
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?
or is there a way to specify the program to use .net 2 runtime instead of .net 4 to run the .com file?
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.
The necessary attribute to set is the useLegacyV2RuntimeActivationPolicy
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0.30319"/>
</startup>
</configuration>
User contributions licensed under CC BY-SA 3.0