[Mono-list] DllNotFoundException

Jonathan Pryor jonpryor at vt.edu
Tue Mar 13 06:49:11 EDT 2007


On Mon, 2007-03-12 at 14:23 +0000, colin at breame.net wrote:
> Using the DllImport attribute to import 'readline' out of libreadline I
> get a DllNotFoundException.  This is what I do:
> 
>  $ gmcs test.cs  # see below
>  $ mono test.exe
>     Unhandled Exception: System.DllNotFoundException: libreadline.so.4
>       at (wrapper managed-to-native) readline_t:readline (string)
>       at readline_t.Main () [0x00000]
>
> My question is; what other things can go wrong loading a library that
> can cause a DllNotFoundException using DllImport?

Mis-compiled libraries can do this, if e.g. libreadline.so required a
symbol from another library, but libreadline.so wasn't linked against
that library, you would get a DllNotFoundException.

To get additional information, run your app with the MONO_LOG_LEVEL and
MONO_LOG_MASK environment variables set:

	$ MONO_LOG_LEVEL=info MONO_LOG_MASK=dll mono test.exe

For reference, your program works correctly on my system (openSUSE 10.2)
when using libreadline.so.5.

The preferred approach (since library names may change between
platforms) would be to do:

	[DllImport ("readline")]
	extern public static string readline(string prompt);

i.e. no version information within the DllImport library name, and then
provide a test.exe.config file that provides the actual library name:

	<configuration>
		<dllmap dll="readline" target="libreadline.so.5"/>
	</configuration>

This allows the version to be easily changed, assuming that the library
ABI hasn't changed in an incompatible manner (as is the case here, as
both libreadline.so.4 and libreadline.so.5 include the `readline'
export).

 - Jon




More information about the Mono-list mailing list