在C#.NET Core 5中使用GDAL软件包导致错误
我已经使用Visual Studio 2019创建了一个.NET Core 5 Web应用程序。我已经在项目中添加了GDAL软件包。当我本地运行Web应用程序时,没有问题,但是当我在IIS上发布应用程序时,会出错。我添加的包装如下: gdal packages
,我的代码就是这样:
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)
});
}
当我在IIS中发布项目时,错误是错误的是这样:
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)
到达此行时发出的错误
Ogr.RegisterAll();
是什么问题?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论