System.BadImageFormatException: Could not load file or assembly

C#64 Bit

C# Problem Overview


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

C# Solutions


Solution 1 - C#

It seems that you are using the 64-bit version of the tool to install a 32-bit/x86 architecture application. Look for the 32-bit version of the tool here:

C:\Windows\Microsoft.NET\Framework\v4.0.30319

and it should install your 32-bit application just fine.

Solution 2 - C#

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

Go and set your choice as shown:

Solution 3 - C#

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.

Solution 4 - C#

I had the same exception installing using correct framework.

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

Solution 5 - C#

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsenzacionaleView Question on Stackoverflow
Solution 1 - C#madd0View Answer on Stackoverflow
Solution 2 - C#DavidView Answer on Stackoverflow
Solution 3 - C#Joseph SnowView Answer on Stackoverflow
Solution 4 - C#woonyView Answer on Stackoverflow
Solution 5 - C#Davut GürbüzView Answer on Stackoverflow