I have installed GDAL and GDAL.Native v3.9.1 packages. Console applications work well, but when I use it in AutoCAD Class Library project, it always raises the exception:
The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.
I am using Visual Studio 2019. The application is being compiled using .NET Framework 4.8.1.
The default GdalConfiguration.cs file is set with execution path of output directory where gdal folder is installed.
// Add directories
AddDllDirectory(nativePath);
AddDllDirectory(Path.Combine(nativePath, "plugins"));
// Set the additional GDAL environment variables.
string gdalData = Path.Combine(gdalPath, "data");
Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
Gdal.SetConfigOption("GDAL_DATA", gdalData); // <------------ Exception!
string driverPath = Path.Combine(nativePath, "plugins");
Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath);
Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath); // <--- Exception!
The lines with comments generate the exception.
Any idea to counter this issue?