System.BadImageFormatException when running Native Client Application in VMware GemFire
search cancel

System.BadImageFormatException when running Native Client Application in VMware GemFire

book

Article ID: 294387

calendar_today

Updated On:

Products

Gemfire VMware Tanzu Gemfire

Issue/Introduction

When running or debugging VMware GemFire Native Client C# Application, you may meet the below exception:

System.BadImageFormatException: 'Could not load file or assembly 'Pivotal.GemFire, Version=10.0.3.2, Culture=neutral, PublicKeyToken=126e6338d9f55e0c' or one of its dependencies. An attempt was made to load a program with an incorrect format.’


Environment

Product Version: 10.0

Resolution



This exception is thrown when the file format of a dynamic link library (.dll file) or an executable (.exe file) doesn't conform to the format that the common language runtime expects.

Since VMware GemFire Native Client 10.x only provides a 64-bit dll file (Pivotal.GemFire.dll) for the C# application and the default target platform in Visual Studio is "x86" or “
AnyCPU”, the exception is thrown under the following condition with the utmost probability:

  • A DLL or executable is loaded as a 32-bit assembly, but it contains 64-bit features or resources. For example, your application relies on COM interop or calls methods in a 64-bit dynamic link library. In this case, your application calls cacheFactory etc.. from Pivotal.GemFire.dll (64-bit).

To address this exception, you can set the project's platform target property to "x64" instead of "x86" or "AnyCPU", then recompile / rebuild the project.

For example:
Visual Studio 2017 Menu [Build]
-->[Configuration Manager...]
-->[Active Solution Platform]
-->Choose [x64], if there is no x64 so far then create a new one as x64 by [<New...>]