WCF Service as Windows Service woes (Windows 7)
Asked Answered
P

2

7

I followed the steps here to make my existing WCF service (already working fine as console application) be Windows Service as well, on my Windows 7 machine which is also my development machine.

No matter what I tried, when doing the last step of using installutil, I'm getting the following message in the command line:

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///[path here]' or one of its dependencies.
An attempt was made to load a program with an incorrect format..

I have my console application main class inherit from ServiceBase and implement OnStart and OnEnd methods.

I have added ProjectInstaller class inheriting from System.Configuration.Install.Installer marked with [RunInstaller(true)] attribute and with the code they supplied in the constructor.

What I already tried that is not mentioned in the above article?

  1. Running the command line as administrator
  2. Navigating to the directory where the EXE file is located and running installutil from there
  3. Giving strong key to the EXE file and all DLL's it's using

Also, I don't get any log file even when specifying it with /LogFile=myLog.txt.

Any ideas are welcome, thanks.

Phytopathology answered 25/10, 2010 at 16:32 Comment(2)
This may seem obvious, but make sure that the InstallUtil.exe is from the correct version of .Net. Sometimes the path environment variable is pointing to another version of .Net, and in that case you will get this error.Pickford
Thanks, I've explicitly added the path of .NET 4 folder to the global windows path and my code is also .NET 4 so that's not the case.Phytopathology
F
6

That smells like a 32-/64-bit problem.

Is your machine 64-bit Windows 7 by any chance?? Does your service somehow reference something 32-bit , like an old COM component or something??

You might need to compile your stuff with the x86 platform in Visual Studio to get it to work properly...

Fractional answered 25/10, 2010 at 16:38 Comment(1)
Right on spot! Never would have guessed. My machine is 64 bit but nowhere in the code I reference anything 32 bit, no COM component.. maybe the default is 32 bit never had the chance to check.Phytopathology
T
3

BadImageFormat exceptions usually occur when the assembly is loaded in an older version of the .NET framework (4.0 assembly on a machine without 4.0). Since you are deploying on the same machine, my guess would be that you are not using the correct version of installutil.

Make sure you use the installutil located here : C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319

Theodore answered 26/10, 2010 at 6:17 Comment(2)
Thanks, your post guided me to the solution: I was using the installutil from C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319 instead of the 32 bit version :SPhytopathology
+1 I was using that version of installutil but "build->platform target" in my windows service project was set to x86 instead of x64. Once I changed this it worked for me.Motivation

© 2022 - 2024 — McMap. All rights reserved.