我被卡住了!我有这个密码
System.Data.Entity.Spatial.DbGeography pointLefttop = h.GreenPoly == null || h.GreenPoly.PointCount < 4 ? null : h.GreenPoly.PointAt(1);
System.Data.Entity.Spatial.DbGeography pointRighttop = h.GreenPoly == null || h.GreenPoly.PointCount < 4 ? null : h.GreenPoly.PointAt(2);
DbGeography linestringBack = pointLefttop == null || pointRighttop == null ? DbGeography.LineFromText("LINESTRING(0 0, 0 0)", 4326) : System.Data.Entity.Spatial.DbGeography.LineFromText("LINESTRING(" + pointLefttop.Longitude + " " + pointLefttop.Latitude + ", " + pointRighttop.Longitude + " " + pointRighttop.Latitude + ")", 4326);其中h.GreenPoly有值{SRID=4326;POLYGON ((-112.51643746 33.49170131, -112.51694319 33.4917729, -112.51685776 33.49219669, -112.51635201 33.49212509, -112.51643746 33.49170131))},并且它的类型是System.Data.Entity.Spatial.DbGeography
但是,我计算linestringBack的行会抛出一个异常
An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll but was not handled in user code
Additional information: Exception has been thrown by the target of an invocation.我试过用
DbGeography linestringBack = pointLefttop == null || pointRighttop == null ? DbGeography.LineFromText("LINESTRING(0.0, 0.0)", DbGeography.DefaultCoordinateSystemId) : System.Data.Entity.Spatial.DbGeography.LineFromText(
string.Format("LINESTRING({0} {1}, {2} {3})",
pointLefttop.Longitude.Value.ToString(CultureInfo.InvariantCulture), pointLefttop.Latitude.Value.ToString(CultureInfo.InvariantCulture), pointRighttop.Longitude.Value.ToString(CultureInfo.InvariantCulture), pointRighttop.Latitude.Value.ToString(CultureInfo.InvariantCulture))
, DbGeography.DefaultCoordinateSystemId);但我还是会犯同样的错误,我也找不出原因。有什么想法吗?
编辑:




发布于 2018-02-20 11:34:30
我找到了解决问题的办法。这似乎是关于Microsoft.SqlServer.Types的一个问题。我使用的是版本11,它在更新到14之后才起作用(在VS2015和VS2017中进行了测试)
对于那些可能会遇到同样问题的人来说:
Microsoft.SqlServer.TypesMicrosoft.SqlServer.Types,如Web.config文件,并将newVersion更改为14.0.0.0https://stackoverflow.com/questions/48822073
复制相似问题