BadImageFormatException error in using InstallUtil tool
Asked Answered
V

3

6

I have created and compiled my windows service using .NET 4.0 So I go to .NET 4.0 folder and say something like this: I copied the bin folder to C drive to make path shorter:

InstallUtil.exe "C:\bin\Debug\MyTestService.exe"

and this is the error I get:

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

So I don't know what to do.

Vauban answered 15/6, 2012 at 23:14 Comment(1)
Hmm - your error message says ....C:\bin Debug... i.e. space rather than \.Autunite
C
17

That error happens when you use the wrong version of installutil. For instance, you are using installutil.exe for .NET 2.0 but your target exe is built with 4.0 or you are using a 32 bit version of installutil on a 64 bit dll/exe.

Corcoran answered 15/6, 2012 at 23:27 Comment(2)
+1 because this is correct but, more importantly, I laughed at your bio.Courtship
This error also happens when you try to load a service from a network location with a .NET version greater than 2.0 without CAS enabled.Renown
V
0

It was built in VisualStudio with "AnyCPU", but I was using X64 version of Install util, I changed it to explicit say built it for X64 machine and got rid of that error. However now it is saying some other error but this error gets solved.

Vauban answered 15/6, 2012 at 23:29 Comment(0)
D
0

I set is as AnyCPU for both 32bit and 64 bit setups. It worked.

Deracinate answered 10/3, 2016 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.