I've created a .net core 5 web application with visual studio 2019. I've added GDAL Packages to my project. When I run the web application locally there are no problems but when I publish the application on the IIS it makes an error. The Packages that I've added are like below: GDAL Packages
and my code is like this :
public IActionResult GetLayerInfo(string fileName)
{
var path = Path.Combine(
Directory.GetCurrentDirectory(), @"wwwroot\files\import",
fileName);
List<string> fList = new List<string>();
GdalConfiguration.ConfigureGdal();
GdalConfiguration.ConfigureOgr();
Ogr.RegisterAll();
DataSource sDatasource = Ogr.Open(path, 1);
if (sDatasource == null)
return null;
OSGeo.OGR.Layer sLayer = sDatasource.GetLayerByIndex(0);
FeatureDefn srcVectorDefn = sLayer.GetLayerDefn();
var type = srcVectorDefn.GetGeomType();
var geomType = wkbGeometryType.GetName(type);
var spatialReference = sLayer.GetSpatialRef();
long fcount = sLayer.GetFeatureCount(1);
var epsg = spatialReference.GetAttrValue("AUTHORITY", 1);
for (int i = 0; i < srcVectorDefn.GetFieldCount(); i++)
{
FieldDefn fieldDefn = srcVectorDefn.GetFieldDefn(i);
fList.Add(fieldDefn.GetName());
}
sDatasource.Dispose();
return Json(new
{
fCount = fcount,
epsg = epsg,
geomType = geomType.Replace("wkb", ""),
fList = fList,
tName = Path.GetFileNameWithoutExtension(fileName)
});
}
and when I publish project in the IIS the error is like this :
An unhandled exception occurred while processing the request.
NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues.
System.Text.Json.Serialization.Converters.TypeConverter.Write(Utf8JsonWriter writer, Type value, JsonSerializerOptions options)
NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues. Path: $.error.TargetSite.DeclaringType.
System.Text.Json.ThrowHelper.ThrowNotSupportedException(ref WriteStack state, NotSupportedException ex)
The Error fired when it reachs this line
Ogr.RegisterAll();
what is the problem ?