[Mono-list] DllImport behaves different between .Net and Mono

Steven Schulze sschulze at vmware.com
Fri Jul 27 13:14:03 EDT 2007

Thanks for the tips.  I guess the reason why Mono has no problem interop'ing
with Windows DLLs is because those are located in the environment's path
somewhere.  I don't want to add my app's folder to the environment's path if
I can avoid it.

But I will follow your link and see what I can find. 

Thanks again for the help!


> -----Original Message-----
> From: mono-list-bounces at lists.ximian.com 
> [mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Andreia Gaita
> Sent: Friday, July 27, 2007 10:00 AM
> To: Mono-list at lists.ximian.com
> Subject: Re: [Mono-list] DllImport behaves different between 
> .Net and Mono
> On 7/27/07, Steven Schulze <sschulze at vmware.com> wrote:
> > On .Net, the DLL is found if I just use the dll name by itself, not 
> > the full path, something like:
> >
> >     [DllImport(@"Foo.dll")]
> >     public static extern bool Bar(string text);
> >
> > On Mono, the DLL is not found unless I hardcode the full path, 
> > something like this:
> >
> >
> >     [DllImport(@"C:\Program Files\MyApp\Foo.dll")]
> >     public static extern bool Bar(string text);
> >
> > This presents a problem because I cannot make assumptions 
> about where 
> > the app will end up when it gets installed.  It seems a bad idea to 
> > hard code the absolute path of anything at compile time.  How can I 
> > make Mono act like .Net in this regard?  Once again, this 
> part of the 
> > code will only get executed when running on Windows.
> There is a lot of code in mono itself that imports 
> windows-specific dlls to interact with the system, and it has 
> no problems doing so with the dll name. Please refer to 
> http://www.mono-project.com/PInvoke#Library_Handling for the 
> proper way of using DllImport on mono.
> You can also check why your mono is not loading the dll by 
> calling, on a mono command prompt:
> X:> set MONO_LOG_LEVEL=debug
> X:> set MONO_LOG_MASK=dll
> X:> mono --debug [nameofprogram.exe] >log.txt
> This will log to a file named log.txt a lot of debug 
> messages, including those about locating dlls, so that if 
> there are problems locating your dll, it should show up there.
> andreia gaita
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com 
> http://lists.ximian.com/mailman/listinfo/mono-list

More information about the Mono-list mailing list