问题描述
现在花了很多令人沮丧的日子来尝试使空间类型DbGeography在Windows Azure上运行.我有一个带Webrole的Windows Azure项目,在其中使用DbGeography.Distance()方法计算距离.在我的本地计算机上可以正常运行,但是一旦发布到Azure,我会得到一个例外:
Have spent a couple of very frustrating days now trying to get the spatial type DbGeography to work on Windows Azure. I have a Windows Azure project with a Webrole where I use the DbGeography.Distance() method to calculate distances. Works lika a charm on my local computer but once published to Azure I get the exception:
Search spa failed message: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticDistance(GeoMarshalData g1, GeoMarshalData g2, EllipsoidParameters ellipsoidParameters, Double& result)
at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticDistance(GeoData g1, GeoData g2, EllipsoidParameters ellipsoidParameters)
at Microsoft.SqlServer.Types.SqlGeography.STDistance(SqlGeography other)
--- End of inner exception stack trace ---
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.Entity.SqlServer.SqlSpatialServices.Distance(DbGeography geographyValue, DbGeography otherGeography)
at System.Data.Entity.Spatial.DbGeography.Distance(DbGeography other)
at DataAccess.Util.DistanceHelper.GetDistanceDictionary(DbGeography spaLocation)
at MvcWebRole.Controllers.SpaController.SearchSpa(String searchString)
我关注了博客帖子 http://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-includes-denali/添加了对Sql.Server.Types和SqlServerSpatial的引用. dll,msvcp100.dll和msvcr100.dll. Thist实际上可以与EF5和Azure网站项目一起使用,但是当我升级到EF6和云服务项目时现在不起作用:(
I have followed the blog post http://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-including-denali/ adding reference to Sql.Server.Types and SqlServerSpatial.dll, msvcp100.dll and msvcr100.dll. Thist actually worked with EF5 and an Azure Website project but not now when I upgraded to EF6 and a Cloud service project :(
推荐答案
System.BadImageFormatException表示您正在部署错误版本的本机程序集(x86与x64).
The System.BadImageFormatException means you are deploying the wrong version of the native assembly (x86 vs x64).
我们已经发布了一个NuGet软件包,以使其更容易-请查看此帖子以获取详细信息 http://blogs.msdn.com/b/adonet/archive/2013/12/09/microsoft-sqlserver-types- nuget-package-spatial-on-azure.aspx .
We've published a NuGet package to make this easier - check out this post for details http://blogs.msdn.com/b/adonet/archive/2013/12/09/microsoft-sqlserver-types-nuget-package-spatial-on-azure.aspx.
这篇关于Windows Azure上的EF 6和空间类型DbGeography的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!