首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TargetInvocationException未被用户代码处理

TargetInvocationException未被用户代码处理
EN

Stack Overflow用户
提问于 2018-02-16 07:35:45
回答 1查看 444关注 0票数 2

我被卡住了!我有这个密码

代码语言:javascript
复制
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的行会抛出一个异常

代码语言:javascript
复制
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.

我试过用

代码语言:javascript
复制
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);

但我还是会犯同样的错误,我也找不出原因。有什么想法吗?

编辑:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-20 11:34:30

我找到了解决问题的办法。这似乎是关于Microsoft.SqlServer.Types的一个问题。我使用的是版本11,它在更新到14之后才起作用(在VS2015和VS2017中进行了测试)

对于那些可能会遇到同样问题的人来说:

  1. 右键单击项目->管理NuGet包.
  2. 在“搜索”选项卡(安装区域)中,键入Microsoft.SqlServer.Types
  3. 点击它并更新到版本14。
  4. Search使用Microsoft.SqlServer.Types,如Web.config文件,并将newVersion更改为14.0.0.0
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48822073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档