2

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?

robbie
  • 1,103
  • 1
  • 10
  • 13
  • Did you rename the executable with the `.com` extension? – Darin Dimitrov Sep 14 '10 at 06:33
  • The .com executable is a third party assembly with a target runtime version of .net v2.0.50727. But doesnt work on machines that have both .NET v2 and v4 (and v3.5). – robbie Sep 14 '10 at 06:45

1 Answers1

1

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>
Jehof
  • 34,674
  • 10
  • 123
  • 155
  • thanks for the quick reply - it's a third party application so I can't modify it. – robbie Sep 14 '10 at 06:46
  • 1
    @robbie. You don´t need to modify the application. Create a .config file for the executable and put the text above in the .config file. – Jehof Sep 14 '10 at 06:53