[Mono-dev] gdal/mono/linux; Native bindings, PInvoke, and tracking TypeLoader exceptions

Jonatan Anauati barakawins at gmail.com
Sun Jan 18 16:46:23 EST 2009


hi

Floris Briolas wrote:
> 
> 
> fevans wrote:
>> 
>> *trim*
>> So when I run the command 'mono GDALInfo.exe' it returns a usage
>> statement. no errors. But when I run 'mono GDALinfo.exe foo.tif', I get a
>> type-loader exception.
>> *trim*
>> 
> 
> This is a yes, me too response, but I've done some analysis on my own. 
> 
> First I was stuck on the DllNotFoundException. My next step was to call
> GDALAllRegister on gdal_fw (Gdal_wrap uses this one).
> (*All code was not cut and pasted*)
> 
> [DllImport("gdal_fw")]
> public static extern void GDALAllRegister();
> 
> And created a small console app that runs this. When run from command line
> it runs just fine, but when run with mono it gave a DllNotFoundException
> (startled). The DLL could be found just fine, the environment path was the
> same, it pointed to the bin of gdal (I've used fwtools 2.2.8) ,.. so what
> could have gone wrong?
> 
> I've PInvoked LoadLibrary from Kernel32
> 
> [DllImport("Kernel32"), SetLastError = true)]
> Public extern static int LoadLibrary(string name);
> 
> When you run :
> Console.WriteLine(LoadLibrary("gdal_fw"));
> With normal .net it runs fine, a handle is returned. under mono it fails
> with error code (getlasterror) 182 meaning invalid ordinal? 
> I've checked the dll dependencies of gdal_fw,.. and long story short, it
> seems the ssleay32.dll fails to load (182) when mono is run. The
> dependencies of ssleay32 load just fine. btw folks these are all unmanaged
> dll's.. 
> 
> Now it's time for me to give up. Hoping someone finds a solution, or an
> explanation why this would occur with mono running.
> 
> regards
> 
> Floris Briolas
> 
> (used mono 2.0.1 on win xp)
> 

Sorry but i don't speek english...
i was found the solution to the "ssleay32.dll" load problem. 

command line> del c:\your mono path\bin\libeay32.dll

and if you run this code snippet:

	[DllImport("Kernel32", SetLastError = true)]
	public extern static int LoadLibrary(string name);
        
        static void Main()
        {
                ...
		Console.WriteLine("libeay32.dll:"  + LoadLibrary("libeay32.dll").ToString
());
		Console.WriteLine("ssleay32.dll: " + LoadLibrary("ssleay32.dll").ToString
());
                ...
        }

command line> mono test.exe

libeay32.dll: 21037056
ssleay32.dll: 22347776

and it seems that works well!

it seems a bug.

regards
-- 
View this message in context: http://www.nabble.com/gdal-mono-linux--Native-bindings%2C-PInvoke%2C-and-tracking-TypeLoader-exceptions-tp17622978p21533484.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list