Windows service throws System.BadImageFormatException in Windows Server 2008, x64, .NET 4, ported from 3.5

I tried to compile the service .exe file as AnyCPU, x86 and x64. It works on my windows 7 x64 box. I am installing with installutil, .NET 4 version.

When I start the service, I get an error message. It does not say anything, but indicates which modules are loaded. Potential interests:

LoadedModule [0] = D: \ yellowbook \ grapevine_service \ grapevinesystemservice.exe LoadedModule 3 = C: \ Windows \ system32 \ KERNEL32.dll LoadedModule 4 = C: \ Windows \ system32 \ KERNELBASE.dll LoadedModule [9] = C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ mscoreei.dll LoadedModule [17] = C: \ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ mscorwks.dll LoadedModule [18] = C: \ Windows \ WinSxS \ amd64_microsoft .vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4927_none_88dce9872fb18caf \ MSVCR80.dll LoadedModule [22] = C: \ Windows \ assembly \ NativeImages_v2.0.50727_64 \ mscorlib \ 9a328af23afa7ffa18afa7ffa18afa7ffa1f823ffa

I can start this service as a console application using the command line, which gives the following:

Unhandled exception: System.BadImageFormatException: it is possible not to load the file or assembly 'grapevinesystemservice.exe' or one of its dependencies. This assembly is built at runtime, but the runtime is currently loaded and cannot be loaded. File Name: 'Grapevinesystemservice.exe'

I tried to hack the registry to force the latest version. There is no effect. I looked at the installed EXE file in thoughtfulness to make sure that it did not get confused on my builds server, but it targets 4.0.30319. My local, build, and test server have 30319 as a version of .NET 4. No one had beta / RC.

, log4net ( .NET 4 ), StructureMap, NoRM (MongoDB), AutoMapper, Newtonsoft.Json DLL , .

+5
4

grapevinesystemservice.exe? 0xA3, , 4.0.

<startup>
  <requiredRuntime version="v4.0.20506" safemode="true"/>
</startup>
+6

DLL AnyCPU. . , .NET x86 x64?, , .

+3

installutil. , .NET 4 Framework, dotNetFx40_Full_setup.exe MSFT. 4.0 Framework PATH.

PATH:

c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;c:\WINDOWS\Microsoft.NET\Framework\v3.5

, .

+1

I found one more reason for this problem: if several .NET frameworks are installed on your web service, then when using installutil.exe, the oldest version will be used by default. This can cause problems if the service you are installing relies on a newer version of the framework.

0
source

All Articles