Skip to main content

This article addresses the System.BadImageFormatException when calling EHLAPI32 DLL.

Problem:

We received the following error when calling EHLAPI32 DLL:

Unhandled Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at Test_EHLAPI32_DLL.WD_ConnectPS(Int32 hInstance, String& ShortName) at Test_EHLAPI32_DLL.Main() below is the code:

Private Declare Function WD_ConnectPS Lib "c:\\program files\\NetManage\\system\\EHLAPI32.DLL" (ByVal hInstance As Integer, ByVal ShortName As String) As Short

Resolution:

The message BadImageFormatException is thrown because of incompatibility when the application loads a DLL. It can be either a 64-bit EXE trying to load a 32-bit DLL, or a 32-bit EXE trying to load a 64-bit DLL. One solution is to compile your vb.NET EXE as 32-bit (X86) and NOT MSIL. To do this, click:

Build > Configuration Manager > Active solution platform >’’>X86> recompile.

Incident Number: 2355806

Old KB# 14672

#SupportTip
#Rumba