Installing Windows Service fails

2.2k views Asked by At

I'm trying to install a .NET 4 Windows Service on a production server: Running InstallUtil.exe gives me this error message:

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

Obviously, it's complaining about the service being written in .NET 4. But the framework is correctly installed on the server as I have other .NET 4 apps running. This is the first time I'm trying to install a service.

I did a bit of googling, and have tried setting the "Target CPU" to "AnyCPU" under Advanced Compiler Settings. What else am I missing?

1

There are 1 answers

1
Jim Mischel On BEST ANSWER

Most likely, you have a bitness mismatch. If this is a 64-bit server, then there's probably a 32-bit DLL somewhere that has the same name as the 64-bit DLL the program is trying to load. Or, on a 32-bit server, there's a 64-bit DLL somewhere.

I've found that when this happens, the application error log (Windows command eventvwr) will tell me where the offending DLL is).