Я установил оба пакета, и они перечислены в моем файле .csproj. Затем я добавил следующий код, который должен прописать путь к переменной окружения, инициализировать новые пакеты, а затем выписать версию и был ли найден драйвер или нет:
Код: Выделить всё
var gdalDir = Path.Combine(baseDir, "gdal");
if (Directory.Exists(gdalDir))
{
var path = Environment.GetEnvironmentVariable("PATH") ?? "";
if (!path.Split(';').Any(p => string.Equals(p, gdalDir, StringComparison.OrdinalIgnoreCase)))
Environment.SetEnvironmentVariable("PATH", gdalDir + ";" + path);
}
GdalBase.ConfigureAll();
Ogr.RegisterAll();
var rel = Gdal.VersionInfo("RELEASE_NAME");
Console.WriteLine($"GDAL version: {rel}");
Console.WriteLine(Ogr.GetDriverByName("OpenFileGDB") != null ? "OpenFileGDB OK" : "OpenFileGDB not found");
Код: Выделить всё
Unhandled exception. System.TypeInitializationException: The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.
---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.
---> System.DllNotFoundException: Unable to load DLL 'gdal_wrap' or one of its dependencies: The specified module could not be found. (0x8007007E)
at OSGeo.GDAL.GdalPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_Gdal(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at OSGeo.GDAL.GdalPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
at OSGeo.GDAL.GdalPINVOKE.SWIGExceptionHelper..ctor()
at OSGeo.GDAL.GdalPINVOKE..cctor()
--- End of inner exception stack trace ---
at OSGeo.GDAL.GdalPINVOKE.AllRegister()
at OSGeo.GDAL.Gdal.AllRegister()
at MaxRev.Gdal.Core.GdalBase.ConfigureGdalDrivers(String gdalDataFolder)
at MaxRev.Gdal.Core.GdalBase.ConfigureAll()
at Program.$(String[] args) in C:\...\Program.cs:line 257
at Program.(String[] args)
Я подтвердил, что библиотеки DLL существуют в папках bin, где они и должны быть.
Я пытался пойти по этому пути, чтобы избежать установки других программ, таких как OSGeo4W. У меня также нет учетной записи ESRI, чтобы получить эти SDK для реализации, которая их использует.
Насколько я понимаю, эти пакеты должны быть полными, но, похоже, чего-то не хватает.
Подробнее здесь: https://stackoverflow.com/questions/798 ... l-exceptio
Мобильная версия