System.BadImageFormatException when installing service

后端 未结 3 497
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 14:14

I am getting below exception when I try to run installer to set up service:

# ./InstallUtil ../../../../Applications/GasPosApp/bin/Wrapper.exe -s ../../../
.         


        
相关标签:
3条回答
  • 2020-12-29 14:45

    You have to use the right version of the InstallUtil. If you are trying install a 32 bit service (x86), use

    c:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
    

    and if you are installing a 64 bit service (x64), use

    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe
    

    Note, that the last specified folder (v4.0.30319) may differ a machine from machine. If you have only an older version of the framework available you can encounter one of the following folders instead - v1.0.xxxx, v1.1.xxxx, v2.0.xxxxx, v3.0, v3.5.

    0 讨论(0)
  • 2020-12-29 14:55

    I agree with all here! This error come, if you are trying to load your application or a one of the refreanced assemblies in an invalid operating system format.

    http://msdn.microsoft.com/en-us/library/system.badimageformatexception(v=vs.80).aspx

    • Check your opearting system format? x86 or x64
    • Check your project build configuration?
    • Check all refreanced assebmlies (VERY IMPORTENET) if one of your loaded refreances (DLL's) is built in the wrong format you will get this error also (Correct me if I'm wrong!).
    • If possible change your VS buid configurartion to AnyCpu.

    Microsoft has created useful tool called CorFlags which can be used to show or set the targeted platform of an managed assembly.

    C:\Program Files\Microsoft.NET\SDK\v2.0\Bin\CorFlags.exe

    Syntax:
    CorFlags filename

    **anycpu** 
    Version   : v4.0.30319
    CLR Header: 2.5
    PE        : PE32
    CorFlags  : 1
    ILONLY    : 1
    32BIT     : 0
    Signed    : 0 
    
    **x86**
    Version   : v4.0.30319
    CLR Header: 2.5
    PE        : PE32
    CorFlags  : 3
    ILONLY    : 1
    32BIT     : 1
    Signed    : 0 
    
    **x64** 
    Version   : v4.0.30319
    CLR Header: 2.5
    PE        : PE32+
    CorFlags  : 1
    ILONLY    : 1
    32BIT     : 0
    Signed    : 0 
    
    0 讨论(0)
  • 2020-12-29 15:03

    This is often an indication of a mismatch between 32 and 64 bit. For instance if Wrapper.exe is compiled as x86 and you install it using the 64 bit InstallUtil the process cannot load the 32 bit Wrapper.exe assembly and will throw a BadImageFormatException.

    The solution is to use the 32 bit InstallUtil placed in the Framework (not Framework64) subfolder of the .NET folder (e.g. C:\Windows\Microsoft.NET\v4.0.30319\Framework if you are using .NET 4 or 4.5).

    0 讨论(0)
提交回复
热议问题