我正在尝试创建一个DbGeometry类型的多边形。它在我的本地计算机上可以正常工作,但是将我的网站托管在Azure Web角色上时,在return语句上出现错误。

码:

string polygon = “POLYGON ((-30.3637216 30.7124139,-30.3632216 30.7124139,-30.3632216 30.7129139,-30.3637216 30.7129139,-30.3637216 30.7124139))”;

return DbGeometry.FromText(polygon, 4326);


例外:

Exception has been thrown by the target of an invocation.


at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at System.Data.SqlClient.SqlSpatialServices.GeometryFromText(String geometryText)

   at Library.Modules.FindMyWay.SpatialFunctions.GetDefaultBox(Decimal latitude, Decimal longitude)

   at Library.Stop.ImportStops(String userName, IEnumerable`1 stops, Int32 companyId) Inner Exception:    at Microsoft.SqlServer.Types.GLNativeMethods.IsValid(GeoMarshalData g, Boolean& result)

   at Microsoft.SqlServer.Types.GLNativeMethods.IsValid(GeoData g)

   at Microsoft.SqlServer.Types.SqlGeometry.IsValidExpensive()

   at Microsoft.SqlServer.Types.SqlGeometry.GeometryFromText(OpenGisType type, SqlChars text, Int32 srid)

   at Microsoft.SqlServer.Types.SqlGeometry.Parse(SqlString s)


您知道为什么这个多边形无效吗?

最佳答案

好吧,我通过将SqlGeometry转换为DbGeometry,以一种about回的方式解决了这个问题:


  is there something like dbgeometry makevalid in .net 4.5


SqlGeometry geom = SqlGeometry.STPolyFromText(new SqlChars(new SqlString(polygon)), 4326);
                 return DbGeometry.FromBinary(geom.STAsBinary().Buffer);


这段代码产生了异常:

Unable to load DLL 'SqlServerSpatial.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)


修理:


  Unable to load DLL 'SqlServerSpatial.dll'


64位dll导致此异常:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)


因此,我必须将32位dll添加到项目中才能使用Azure。

结果:现在还好,但是我仍然不确定DbGeometry为什么不能在Azure上运行,也不确定为什么64bit dll也不能在Azure上运行。

关于c# - 在Azure Web角色上托管时,SqlGeometry/DbGeometry是无效异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17977391/

10-09 01:18