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

Robert Jordan robertj at gmx.net
Fri Jul 27 12:07:11 EDT 2007


Steven Schulze wrote:
> Hi all,
>  
> I am using DllImport to interop with a C DLL I wrote in order to communicate
> with automation tools.  Note that this is only needed on Windows. All works
> well but I have this one problem...
>  
> 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.


Assure that the current directory is C:\Program Files\MyApp\. You can
do this using a Windows shortcut during installation.

Please report this bug at http://mono-project.com/Bugs
product "runtime", component "interop".


Robert



More information about the Mono-list mailing list