c# - 在 Azure Web 角色上托管时出现 SqlGeometry/DbGeometry Isvalid 异常

标签 c# entity-framework-5 .net-4.5 azure-sql-database azure-web-roles

我正在尝试创建一个 DbGeometry 类型的多边形。它在我的本地计算机上运行良好,但在 Azure Web 角色上托管我的网站时,返回语句出现错误。

代码:

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):

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 以一种迂回的方式解决了这个问题:

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 上运行,也不确定为什么 64 位 dll 也不能在 Azure 上运行。

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

相关文章:

c# - 在 TeamCity 中包含 NuGet 包

.net - 适用于 .NET 4.5 的 Windows 7 SDK?

c# - 在等待 WaitHandle 时运行消息循环

c# - 我可以在 C# 项目上使用 .rc 资源文件吗?

c# - 无需 Visual Studio 即可运行 Azure 计算模拟器和存储并启动网站

c# - 在 C# 5 中表示异步序列

ASP.NET MVC 4 - 在编辑和保存数据时如何使用 View 模型

entity-framework - 发布 Web 对话框未将我的 Entity Framework 5 上下文检测为 Code First

visual-studio-2012 - Entity Framework 5 和 Amazon RDS - "The underlying provider failed on Open."

c# - ResourceManager.GetString() FileNotFound 异常