0

There is a C-Funktion which I use as a DLL. The function is exported by

__declspec(dllexport) uint8_t *SomeFunction(uint8_t *a);

In the respective header file.

The wrapper imports the function with

[DllImport("SomeCFunction.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SomeFunction")]
private static extern IntPtr SomeFunction(Byte[] array1);

The wrapper has a method with which contains the call of that function

public unsafe Byte[] SomeFunction(Byte[] array1, Byte[] array2)
{
    IntPtr parray2 = CalculateKeyFromSeed(array1);

}

Now I get the Error when executing the step in TestStand:

An exception occurred inside the call to .NET member 'SomeFunction': System.BadImageFormatException: Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B) bei SomeFunctionWrapperNameSpace.WrapperClass.SomeFunction(Byte[] array1) bei WrapperNameSpace.WrapperClass.SomeFunction(Byte[] array1, Byte[] array2) in SomeFunctionWrapper.cs:Zeile 33. bei SomeFunction(Byte[] array1, Byte[] array2) in SomeFunction.cs:Zeile 39.

Some idea how I get TestStand accepting this DLL?

Christian
  • 13
  • 5
  • check the bitness, Is the dll 64bit? is the c# dll 64bit? what about the TestStand process? – James Oct 08 '15 at 14:49
  • You have been right! My TestStand Version is a 64bit one. In the properties of the C-DLL Project in VS2010 the Configuration Manager only allows 32bit xor 64bit. So I had to Change to 64bit. Another Problem was that my C# dll, which I used in TestStand was not set on "any CPU", but my Wrapper C# DLL was. FAZIT: set all C# Dll on "any CPU" and the C-Dll on what TestStand Version you have. – Christian Oct 09 '15 at 09:13
  • I'll put that as the answer then! – James Oct 09 '15 at 09:17

1 Answers1

1

BadImageFormat normally means there is a mismatch in the bitness of one of the parts.

These need to match, you have 3 parts to check

  • Is the C dll 64-bit?
  • Is the C# dll 64-bit? (AnyCPU should be OK here AFAIK)
  • Is the TestStand process 64-bit?
James
  • 9,774
  • 5
  • 34
  • 58