[Gdal-dev] Error when invoking AllRegister in C#

Simon Perkins sy at perkins.net
Tue Sep 4 19:02:10 EDT 2007


Dennis wrote:
> I'm working on a C# project that needs to use gdal.   However, 
> whenever I try to invoke Gdal.AllRegister I get this error:  The type 
> initializer for OSGeo.GDAL.GdalPINVOKE threw an exception.  This is 
> surprising because I was able to run one of the sample programs 
> successfully and my project has the same references as the sample 
> program.  The only difference I can tell between the two projects is 
> that mine is a forms project while the sample is a console project 
> (and I can't see why that would make a difference).
>
> Any ideas what might be causing this?
>

The usual cause for this is that one of the GDAL DLLs that you need is 
not being found at runtime. If you look at the inner exception details 
you may see a message about DLLs.

The gdal_csharp.dll assembly you added a reference to in your project is 
merely a front for gdal_wrap.dll, which in turn calls gdal14.dll to do 
the work.

You need to make sure that the GDAL DLL  and the "wrap" DLLs are in a 
place that they can be found at runtime. This usually means they either 
have to be in the same directory as your applications, or in a directory 
that is listed in your PATH. Note that this is all in addition to adding 
a reference to the GDAL C# assemblies.


Cheers,

Simon




More information about the Gdal-dev mailing list