Bug 42134 - DllNotFoundException for x64 Mono on Windows, x86 Mono ok on Windows, both ok on Linux Red Hat and .NET
Summary: DllNotFoundException for x64 Mono on Windows, x86 Mono ok on Windows, both ok...
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: 4.2.0 (C6)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Niklas Therning
Depends on:
Reported: 2016-06-23 22:12 UTC by Greg T
Modified: 2017-10-20 17:28 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

zip file containing the VS2015 project, debug notes, and PDF file showing results (491.52 KB, application/x-zip-compressed)
2016-06-23 22:12 UTC, Greg T

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Greg T 2016-06-23 22:12:51 UTC
Created attachment 16467 [details]
zip file containing the VS2015 project, debug notes, and PDF file showing results


When running the attached small C# project under x64 Mono ( on Windows (Win7 Pro) from Visual Studio 2015 a DllNotFoundException occurs when calling a Fortran dynamic library (using "dllimport" for P/Invoke).  The project works correctly under x86 Mono, and correctly under .NET for both x86 and x64 on Windows from VS2015.  I copy the executable to Linux (Red Hat 6.8) and it runs correctly under x64 (calls a native Fortran shared object).

I am using the MonoHelper add-in to VS2015 to run Xbuild to get the C# "CallDll.exe" executable.  I also ran the exe from the Mono command line using "mono --debug CallDll.exe > mono_debug.txt" to check the file path being searched for the "fortlog.dll" file.  The debug output shows that it is searching in the correct directory but does not find the "fortlog.dll".  For this simple reproducing case I am not passing any arguments to the Fortran routine, just testing the "dllimport" syntax (for P/Invoke) from C# to Fortran.

The attached zip file and attached PDF file show the expected output and error output.  The "CallDll" project has a single form with a button and text box.  The expected result when clicking the button is to increment count and get the message "called the Fortran shared library..." and for the Fortran routine to write text and list of numbers to the "writelog.log" text file.  The error output for x64 Mono on Windows is the DllNotFoundException, which gets trapped in the try-catch block.

The zip file contains the VS2015 project with the exe and dll files in the x64 ad x86 sub folders along with the "writelog.log" text file in the x86 folder, and the "mono_debug.txt" output in the x64 folder.

Since this test case (and other C# calling Fortran under Mono cases) work except under x64 Mono on Windows, we can run the x64 case on Linux, but it would be convenient to be able to test x64 on Mono on Windows from VS2015.

Let me know if additional information would help.

Thanks for your help.
Comment 1 Niklas Therning 2016-10-10 07:00:25 UTC

Please try with the most recent release of Mono (4.6.x). The state of Mono on Windows x64 has improved immensely the last couple of months.
Comment 2 Greg T 2016-10-13 14:07:27 UTC
Hi Niklas,

Thank you for the notice that a new Mono update is available.  I'll give it a try.

Comment 3 Ludovic Henry 2017-09-06 18:10:10 UTC
Did you have a chance to try latest Mono? If so, did it fix your bug? Thank you
Comment 4 Greg T 2017-09-07 14:02:20 UTC
Hi Henry,

Thanks for the update.  I have not yet had a chance to install mono on Windows to check if it works with x64.  That is still on my to do list when time permits.  

Were you able to used the attached small program on Windows x64?

Comment 5 Greg T 2017-10-20 17:28:20 UTC
Hi Henry, Niklas,

I finally had time to download Mono 5.4.0 for Windows x64, installed it, and reran the test case I had previously attached to this ticket.  It runs fine from the "Open Mono x64 Command Prompt" window.  Thanks for your help.