[c#] System.BadImageFormatException: Could not load file or assembly

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe C:\_PRODUKCIJA\D
ebug\DynamicHtmlTool.exe
Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\_PRO
DUKCIJA\Debug\DynamicHtmlTool.exe' or one of its dependencies. An attempt was ma
de to load a program with an incorrect format..

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>

service is x86 compiled even both computers are x64 and it works on my computer. Here in server where is win 2008 i get this error.

i try solutions from google but none works.

Like write here i have x86 project http://www.davesquared.net/2008/12/systembadimageformatexception-on-64-bit.html

This question is related to c# 64-bit

The answer is


My cause was different I referenced a web service then I got this message.

Then I changed my target .Net Framework 4.0 to .Net Framework 2.0 and re-refer my webservice. After a few changes problem solved. There is no error worked fine.

hope this helps!


Try to configure the setting of your projects, it is usually due to x86/x64 architecture problems:

Go and set your choice as shown:


I found a different solution to this issue. Apparently my IIS 7 did not have 32bit mode enabled in my Application Pool by default.

To enable 32bit mode, open IIS and select your Application Pool. Mine was named "ASP.NET v4.0".
Right click, go to "Advanced Settings" and change the section named: "Enabled 32-bit Applications" to true.

Restart your web server and try again.

I found the fix from this blog reference: http://darrell.mozingo.net/2009/01/17/running-iis-7-in-32-bit-mode/

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.


I had the same exception installing using correct framework.

My solution was running cmd as administrator .... then it worked fine.