I want my C # application to conditionally run its own method. Having decided at run time whether to run either the x86 or x64 version of the dll.
This question explains how to select a 32-bit or 64-bit bit at compile time, but this does not help. I want to make a decision at runtime.
I am currently doing the following:
[SuppressUnmanagedCodeSecurity] internal static class MiniDumpMethods { [DllImport("dbghelp.dll", EntryPoint = "MiniDumpWriteDump", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MiniDumpWriteDump( IntPtr hProcess, uint processId, SafeHandle hFile, MINIDUMP_TYPE dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam); [DllImport("dbghelpx86.dll", EntryPoint = "MiniDumpWriteDump", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MiniDumpWriteDumpX86( IntPtr hProcess, uint processId, SafeHandle hFile, MINIDUMP_TYPE dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam); }
But when I try to call the x86 method, I get an error:
Unhandled Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at <exeName>.MiniDumpMethods.MiniDumpWriteDumpX86(IntPtr hProcess, UInt32 processId, SafeHandle hFile, MINIDUMP_TYPE dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam)
Any idea how I can conditionally download either x86 or x64 version for dll?
(Note: dbghelpx86.dll is the x86 version of dbghelp.dll that I renamed)
thanks