- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am attempting to use a DLL created in Visual Fortran 2011 -- XE12.0, whenever the C# calling routine attempts to load the DLL I get the following error. "
An unhandled exception of type 'System.BadImageFormatException' occurred in expand_MISC.exe
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"
I have created simplified DLLs and C# routines to attempt to find a work around but all fail with same error.
The debug output of a recent attempt was:
'expand_MISC.exe': Loaded 'C:\FORTRAN\Work_Source\Intel_qikest\ClassLibrary1\ClassLibrary1\bin\Debug\expand_MISC.exe', No native symbols in symbol file.
'expand_MISC.exe': Loaded 'C:\Windows\System32\ntdll.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\mscoree.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\kernel32.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\apphelp.dll', Exports loaded.
'expand_MISC.exe': Unloaded 'C:\Windows\System32\apphelp.dll'
'expand_MISC.exe': Loaded 'C:\Windows\System32\advapi32.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\sechost.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoreei.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\gdi32.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\user32.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\lpk.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\usp10.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\imm32.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\msctf.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\msvcr110_clr0400.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_64\mscorlib\abf62e6545d2802fc60286678a67e6bf\mscorlib.ni.dll', Cannot find or open the PDB file
'expand_MISC.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'expand_MISC.exe': Loaded 'C:\Windows\System32\ole32.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Exports loaded.
'expand_MISC.exe' (Managed (v4.0.30319)): Loaded 'C:\FORTRAN\Work_Source\Intel_qikest\ClassLibrary1\ClassLibrary1\bin\Debug\expand_MISC.exe', Symbols loaded.
'expand_MISC.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clrjit.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Exports loaded.
'expand_MISC.exe': Loaded 'C:\FORTRAN\Work_Source\Intel_qikest\MISC2BOM3\MISC2BOM3\Debug\MISC2BOM3.dll', Binary was not built with debug information.
'expand_MISC.exe': Unloaded 'C:\FORTRAN\Work_Source\Intel_qikest\MISC2BOM3\MISC2BOM3\Debug\MISC2BOM3.dll'
'expand_MISC.exe': Loaded 'C:\FORTRAN\Work_Source\Intel_qikest\MISC2BOM3\MISC2BOM3\Debug\MISC2BOM3.dll', Binary was not built with debug information.
'expand_MISC.exe': Unloaded 'C:\FORTRAN\Work_Source\Intel_qikest\MISC2BOM3\MISC2BOM3\Debug\MISC2BOM3.dll'
First-chance exception at 0x000007fefd15940d (KernelBase.dll) in expand_MISC.exe: Microsoft C++ exception: EEException * __ptr64 at memory location 0x001fddd8..
A first chance exception of type 'System.BadImageFormatException' occurred in expand_MISC.exe
'expand_MISC.exe': Loaded 'C:\Windows\System32\version.dll', Exports loaded.
An unhandled exception of type 'System.BadImageFormatException' occurred in expand_MISC.exe
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
The thread 'Win64 Thread' (0xb8c) has exited with code -1073741510 (0xc000013a).
The thread 'Main Thread' (0x2720) has exited with code -1073741510 (0xc000013a).
The thread 'Win64 Thread' (0x24c0) has exited with code -1073741510 (0xc000013a).
The thread 'Win64 Thread' (0x4a8) has exited with code -1073741510 (0xc000013a).
The program '[8164] expand_MISC.exe: Native' has exited with code -1073741510 (0xc000013a).
The program '[8164] expand_MISC.exe: Managed (v4.0.30319)' has exited with code -1073741510 (0xc000013a).
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
David Caruthers,
Can you confirm your .NET platform configuration is consistent with the Fortran DLL? For example, .NET target with x64 platform is invoking the Fortran DLL with x64 build or .NET with x86 is calling the Fortran DLL with Win32 configuration? Note if your .NET application uses the "Any CPU" setting, it can cause issues on 64-bit Windows OS and it may not resolve to the right DLL. My preference is to avoid "Any CPU" configuration for my .NET solutions.
If everything looks kosher to you, then it will help if you can provide a simple reproducer for your problem for what you're trying is being performed successfully by others.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
here is a very simple reproducer for the problem. The UNSAFE function is to allow handling of FORTRAN returned arrays and records as would be the case in the full blown code.
FORTRAN:
! Simple_test.f90
!
! FUNCTIONS/SUBROUTINES exported from Simple_test.dll:
! Simple_test - subroutine
!
subroutine SIMPLE_TEST(IinOut)
! Expose subroutine Simple_test to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT::SIMPLE_TEST
! Variables
integer*4 IinOut
IinOut = InOut * 20
! Body of Simple_test
end subroutine SIMPLE_TEST
FOETRAN Configuration:
build as command line: /OUT:"Debug\Simple_test.dll" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"C:\FORTRAN\work_source\intel_qikest\Simple_test\Debug\Simple_test.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\FORTRAN\work_source\intel_qikest\Simple_test\Debug\Simple_test.pdb" /SUBSYSTEM:WINDOWS /IMPLIB:"C:\FORTRAN\work_source\intel_qikest\Simple_test\Debug\Simple_test.lib" /DLL
>NET 4.0 x64
C# calling program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;/* Provides mappings between C# and native code */
namespace C2FORT1
{
class Program
{
/***** FORTRAN DLL interface definitions -- allow using AES FORTRAN routnes suitably wrapped *****/
[DllImport("C:\\FORTRAN\\Work_Source\\Intel_qikest\\Simple_test\\Debug\\Simple_test.dll")]
/* Import from DLL, the C# compiler provides a rudimentry check of the signature */
unsafe public static extern void SIMPLE_TEST(ref Int32 Ivalue);
unsafe public static Int32 getIvalue(Int32 Ivalue)
{
Int32 iFORTvalue;
iFORTvalue = Ivalue;
SIMPLE_TEST(ref iFORTvalue);
Console.WriteLine("Returned safely from MISC2BOM with {0} for iFORTvalue",
iFORTvalue);
return iFORTvalue;
}
static void Main(string[] args)
{
Int32 Ivalue = 5;
int iretn = getIvalue(Ivalue);
Console.WriteLine(" Calling value = {0}, FORTRAN value = {1}", Ivalue, iretn);
}
}
}
PlatformL x64
ERROR messages:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
debug output:
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\FORTRAN\work_source\intel_qikest\C2FORT1\bin\x64\Debug\C2FORT1.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 'vshost.NotifyLoad' (0x1430) has exited with code 0 (0x0).
The thread '<No Name>' (0x2280) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x2684) has exited with code 0 (0x0).
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\FORTRAN\work_source\intel_qikest\C2FORT1\bin\x64\Debug\C2FORT1.exe', Symbols loaded.
A first chance exception of type 'System.BadImageFormatException' occurred in C2FORT1.exe
'C2FORT1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.BadImageFormatException' occurred in C2FORT1.exe
A first chance exception of type 'System.BadImageFormatException' occurred in C2FORT1.exe
A first chance exception of type 'System.BadImageFormatException' occurred in C2FORT1.exe
A first chance exception of type 'System.BadImageFormatException' occurred in C2FORT1.exe
The program '[8840] C2FORT1.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
I hope that this will give a clue.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here are the debug error notices when debugged with debug unmanaged code turned on. Same basic error as before.
'C2FORT1.exe': Loaded 'C:\FORTRAN\Work_Source\Intel_qikest\C2FORT1\bin\x64\Debug\C2FORT1.exe', No native symbols in symbol file.
'C2FORT1.exe': Loaded 'C:\Windows\System32\ntdll.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\mscoree.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\kernel32.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\apphelp.dll', Exports loaded.
'C2FORT1.exe': Unloaded 'C:\Windows\System32\apphelp.dll'
'C2FORT1.exe': Loaded 'C:\Windows\System32\advapi32.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\sechost.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoreei.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\gdi32.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\user32.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\lpk.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\usp10.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\imm32.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\msctf.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\msvcr110_clr0400.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_64\mscorlib\abf62e6545d2802fc60286678a67e6bf\mscorlib.ni.dll', Cannot find or open the PDB file
'C2FORT1.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'C2FORT1.exe': Loaded 'C:\Windows\System32\ole32.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Exports loaded.
'C2FORT1.exe' (Managed (v4.0.30319)): Loaded 'C:\FORTRAN\work_source\intel_qikest\C2FORT1\bin\x64\Debug\C2FORT1.exe', Symbols loaded.
'C2FORT1.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clrjit.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Exports loaded.
'C2FORT1.exe': Loaded 'C:\FORTRAN\Work_Source\Intel_qikest\Simple_test\Debug\Simple_test.dll', Symbols loaded.
'C2FORT1.exe': Unloaded 'C:\FORTRAN\Work_Source\Intel_qikest\Simple_test\Debug\Simple_test.dll'
'C2FORT1.exe': Loaded 'C:\FORTRAN\Work_Source\Intel_qikest\Simple_test\Debug\Simple_test.dll', Symbols loaded.
'C2FORT1.exe': Unloaded 'C:\FORTRAN\Work_Source\Intel_qikest\Simple_test\Debug\Simple_test.dll'
First-chance exception at 0x000007fefd15940d (KernelBase.dll) in C2FORT1.exe: Microsoft C++ exception: EEException * __ptr64 at memory location 0x005edf38..
A first chance exception of type 'System.BadImageFormatException' occurred in C2FORT1.exe
'C2FORT1.exe': Loaded 'C:\Windows\System32\version.dll', Exports loaded.
An unhandled exception of type 'System.BadImageFormatException' occurred in C2FORT1.exe
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
'C2FORT1.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\diasymreader.dll', Exports loaded.
The thread 'Win64 Thread' (0x1dc8) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1cd4) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x26d4) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x25cc) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0x1978) has exited with code 0 (0x0).
The thread 'Win64 Thread' (0xf54) has exited with code 0 (0x0).
The program '[7796] C2FORT1.exe: Native' has exited with code 0 (0x0).
The program '[7796] C2FORT1.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
David Caruthers wrote:
...
FORTRAN Configuration:
build as command line: /OUT:"Debug\Simple_test.dll" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"C:\FORTRAN\work_source\intel_qikest\Simple_test\Debug\Simple_test.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\FORTRAN\work_source\intel_qikest\Simple_test\Debug\Simple_test.pdb" /SUBSYSTEM:WINDOWS /IMPLIB:"C:\FORTRAN\work_source\intel_qikest\Simple_test\Debug\Simple_test.lib" /DLL
>NET 4.0 x64
..
The question is what Fortran command settings are you using: is it based on IA-32 mode or Intel-64? You need to make sure it is Intel-64.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks had to override some of the company default installation things to make this go. now get true 64 bit compiles etc.
David

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page