using DLL in Vista 64bit, Bad Image Format Exception
-
I am trying to use this DLL in Vista 64 bit version. It give me error (exception) "BadImageFormatException was unhandled". The same DLL works fine with 32 bit version (Vista). Anyone has come across it, is there a way to resolve it?
Assuming this dll you're using is one you've built, When you built the dll, was it built using the AnyCPU platform? If so, you must ensure there are not 32-bit specific references to your code. (Many COM objects, native dlls, 3rd party libs are all 32-bit specific. You may need to obtain 64-bit specific versions of those components.) Another thing to try is build the dll using x64 as the platform.
Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Assuming this dll you're using is one you've built, When you built the dll, was it built using the AnyCPU platform? If so, you must ensure there are not 32-bit specific references to your code. (Many COM objects, native dlls, 3rd party libs are all 32-bit specific. You may need to obtain 64-bit specific versions of those components.) Another thing to try is build the dll using x64 as the platform.
Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
Yes it is my own dll and it was built using 'any cpu' option. Also I tried the x64bit but it gave the same error. Sometime it give NotValidEntryPointException, othertimes it gives BadImageException. It work fine on 32bit wondows though. I am not deep into COM so i do not know what can go wrong there.
-
Yes it is my own dll and it was built using 'any cpu' option. Also I tried the x64bit but it gave the same error. Sometime it give NotValidEntryPointException, othertimes it gives BadImageException. It work fine on 32bit wondows though. I am not deep into COM so i do not know what can go wrong there.
Does your dll use any 3rd party libraries? COM objects? Does it make P/Invoke calls into native dlls?
Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Does your dll use any 3rd party libraries? COM objects? Does it make P/Invoke calls into native dlls?
Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Yes it does use third party libraries. I am new to c# so I do not know much about p/invoke but yes it uses p/invoke as well. I do not think it uses COM objects. Again it is working on on 64bit machine (not a vista one).
Can you post some of your P/Invoke calls? Most likely it's an issue with those.
Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Can you post some of your P/Invoke calls? Most likely it's an issue with those.
Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Here is the format of one such call.
[DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)] internal static extern float a_function(int n, [In] float[] x, int incX);
Thanks.Yep, that looks problematic: the first value is an integer. In .NET, this will always be 4 bytes. In native code, however, this will be either 4 bytes on a 32-bit system, or 8 bytes on a 64 bit system (IIRC). Instead of an integer, pass in an IntPtr. Your function would look something like this:
[DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)]
internal static extern float a_function(IntPtr n, [In] float[] x, IntPtr incX);Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Yep, that looks problematic: the first value is an integer. In .NET, this will always be 4 bytes. In native code, however, this will be either 4 bytes on a 32-bit system, or 8 bytes on a 64 bit system (IIRC). Instead of an integer, pass in an IntPtr. Your function would look something like this:
[DllImport(dllName, ExactSpelling=true, SetLastError=false, CallingConvention=CallingConvention.Cdecl)]
internal static extern float a_function(IntPtr n, [In] float[] x, IntPtr incX);Tech, life, family, faith: Give me a visit. From my latest post: "It's sobering to watch: the whole country stops for 2 minutes as a siren is blast to remember the 22,437 victims of terror and soldiers who died in defense of Israel..." The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
I will try it with a new test program to see if it works. Now apparentely the code should work because i am getting error from DLL not from native code. The client program basically does not find the necessary signature or entry point inside DLL. It does not reach the native code part at all. The DLL is just a wrapper of the native code. I will give it a try though and will let you know what happens.