Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing .net 4 project on target server - Error System.BadImageFormatException

Tags:

.net

.net-4.0

I have installed the .net 4 framework on one of my servers.

When I run an installation project created in Visual Studio - get the following error:

Error 1001 Exception occurred while initializing the installation. System.BadImageFormatException: Could not load file or assembly or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

I've definately installed the .net 4 framework on the target machine - what's going on?

like image 862
Alex Avatar asked Apr 20 '10 14:04

Alex


People also ask

How to resolve system BadImageFormatException?

Restart your web server and try again. Additionally, you can change the settings on Visual Studio. In my case, I went to Tools > Options > Projects and Solutions > Web Projects and checked Use the 64 bit version of IIS Express for web sites and projects - This was on VS Pro 2015. Nothing else fixed it but this.

What is System BadImageFormatException?

Solution. A System. BadImageFormatException error often occurs when a 64-bit assembly is opened by a 32-bit application. In this case, Visual Studio is a 32-bit application and the Design view is attempting to load a 64-bit assembly. Visual Studio assemblies are located in the project references tree.


2 Answers

I eventually found the solution to this, and blogged about it: Deploying .NET 4 Project – Error 1001 (System.BadImageFormatException)


Update: Copied the content from the blog:

"After attending the UK Tech Days events last week in London, I was keen to jump on the Visual Studio 2010 and .net 4.0 bandwagon.

I converted some of our projects here at Crocus to the .net 4 framework (which was incredibly easy – nothing broke!) I even took advantage of some of the quick to implement features in .net 4, and converted some of our massively over-ridden methods to use optional parameters.

One project in particular is a Windows Service, that sends out purchase orders on a schedule. (I recently wrote about how this broke due to Quartz.net expecting a UTC start time)

This has a Visual Studio deployment project associated with it.

After building the newly upgraded .net 4 version of the project, and deploying the .msi file to our target server, I got the following error:

Error 1001 Exception occurred while initializing the installation. System.BadImageFormatException: Could not load file or assembly or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Now, I had definitely upgraded said server to .net 4 (twice, as a matter of fact – after the first time i received this error!)

After some Googling, some people were saying to change the platform target on my assemblies, which i did, to no avail.

I eventually discovered the problem.

You need to set the .NET Framework Launch Condition

Here’s how to do it:

  1. Right click on your deployment project in solution explorer. In the context menu, select View -> Launch Conditions
  2. Under 'Version' choose '.NET Framework 4'

After rebuilding and deploying my setup file, everything worked fine."

like image 155
Alex Avatar answered Nov 02 '22 20:11

Alex


  1. Click on the installer project, then go to Project>Properties.
  2. Click on the Prerequisites button
  3. Check the “Microsoft .NET Framework 4 (x86 and x64)” box and uncheck the previous version of the framework
  4. Hit ok on the Prerequisites window and on the the properties window.
  5. Right click on the installer project and go to View>Launch Conditions
  6. Highlight the .NET Framework condition and update the following fields in the properties box
    a. InstallURL : http://msdn.microsoft.com/en-us/netframework/aa569263.aspx
    b. Version: .NET Framework 4
  7. Rebuild the installer
like image 26
Kevin Avatar answered Nov 02 '22 20:11

Kevin