Search code examples
gdal

Unable to load DLL 'ogr_wrap' or one of its dependencies


In my C# project, I have added GDAL and GDAL.Native nuget packages. When attempting

Geometry h = Ogr.CreateGeometryFromJson(geometry);

I get

The type initializer for 'OSGeo.OGR.OgrPINVOKE' threw an exception
Unable to load DLL 'ogr_wrap' or one of its dependencies

ogr_wrap is there, not with all other dlls like ogr_csharp.dll, but in gdal/x64 subdir

Some other GDAL methods like GetGeoTransform, GetRasterBand etc work correctly.

Am I missing something?

GDAL is 3.7.2, VS is 17.8.2, .NET 8.0 (same behaviour in 7.0).


Solution

  • Make sure you have included the following in your code before using Ogr:

    GdalConfiguration.ConfigureGdal();
    GdalConfiguration.ConfigureOgr();