[Mono-list] DllImport behaves different between .Net and Mono
jonpryor at vt.edu
Fri Jul 27 13:50:49 EDT 2007
On Fri, 2007-07-27 at 10:24 -0700, Steven Schulze wrote:
> According to the link you provided, it says the DLL is searched like this:
> 1) The directory from which the application loaded.
> 2) The current directory.
> 3) ...
> At least from my testing, neither of the first two cases work as stated.
The first case should work as stated. The fundamental problem is this:
rem .NET invocation:
rem Mono invocation
In the former, YourAppName.exe is the application which loaded, so "Path
\To" is the directory that Win32 uses when looking for libraries.
For the latter case, *mono* is the application which is loaded, so
Mono's application directory is the directory that Win32 uses when
looking for libraries.
Which is where the current working directory would come in...except that
you NEVER want to rely on the current working directory, because it will
change (based on where the user was when they start your app). So even
if it worked, it's not a decent solution.
So you fall back to modifying %PATH%, etc., which is also ugly...
I thought Mono had a hack in place to load libraries from the assemblies
directory instead of just relying on LoadLibrary(), but I may be
In short, if Mono isn't properly finding the directory, what you'll
likely need to do (for now) is create a wrapper .cmd script file which
sets %PATH% to include the application's directory; this way Mono will
be able to LoadLibrary() your DLLs (as LoadLibrary() will find them).
More information about the Mono-list