使用地理空间操作时生产中的BadImageFormatException

时间:2016-08-16 21:09:26

标签: c# sql-server geospatial

我正在开发一个Windows服务项目,它使用EF的地理空间功能和 SQLServer 。我在制作中使用SQL Server 2014。我在服务器上安装了SQLSysClrTypes.msi至少2-3次,并且NuGet正在管理我的Microsoft.SqlServer.Types包。我想这不会是x86 / x64问题,因为我有一个 SqlServerTypes 文件夹,其中, x86 以及 x64 DLL驻留在各自的文件夹中(即x86和x64)。

我面临的详细例外情况如下:

Inner Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIntersects(GeoMarshalData g1, GeoMarshalData g2, Double eccentricity, Boolean& result)
   at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIntersects(GeoData g1, GeoData g2, Double eccentricity)
   at Microsoft.SqlServer.Types.SqlGeography.STIntersects(SqlGeography other)
   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.Intersects(DbGeography geographyValue, DbGeography otherGeography)
   at System.Data.Entity.Spatial.DbGeography.Intersects(DbGeography other)

有人可以告诉我为什么我可能会遇到这个例外吗?

这是Microsoft提供的有关解决此错误的最佳方法: https://msdn.microsoft.com/en-us/library/k7137bfe.aspx

1 个答案:

答案 0 :(得分:0)

当您尝试在x64进程中加载​​x86 DLL时,会出现异常,反之亦然。有一个32位和64位的Microsoft.SqlServer.Types DLL,你需要正确的DLL。不记得这最后一项,但你必须测试,但是一些本机DLL甚至不能与AnyCPU一起使用,你必须特别匹配。