为什么我得到FatalExecutionEngineError

时间:2016-05-31 13:17:11

标签: c# entity-framework-6 .net-4.6

我正在运行此代码

var existing =( from r in DB.Database.Entities.OfType<DBWorkReport>()
              where Math.Round(r.Location.Latitude ?? 0, 6) == Math.Round(latitude, 6)
              && Math.Round(r.Location.Longitude ?? 0, 6) == Math.Round(longitude, 6)
              && r.WorkType.Description == type
              select r).FirstOrDefault();

错误也发生在一个简单的 DB.Database.Entities.ToList();

其中

DB

public class DatabaseInterface : INotifyPropertyChanged
{

    public void Initialise()
    {
        if (Database == null)
        {
            Database = new DataDBEntities();
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private DataDBEntities _Database;
    public static readonly PropertyChangedEventArgs DatabaseProperty = new PropertyChangedEventArgs(nameof(Database));


    public DataDBEntities Database
    {
        get { return _Database; }
        set
        {
            _Database = value;
            PropertyChanged?.Invoke(this, DatabaseProperty);
        }
    }

实体

public virtual DbSet<DBEntity> Entities { get; set; }

DBWorkReport是

public partial class DBWorkReport : DBEntity

和r.Location是DBGeography

然而,当我运行它,它的投掷

  

发生FatalExecutionEngineError HResult = -2146233082
  消息=类型的异常&#39; System.ExecutionEngineException&#39;是   抛出。的InnerException:

enter image description here

引用MSDN:

  

FatalExecutionEngineError:   此类型先前表示未指定的致命错误   运行。运行时不再引发此异常,因此此类型为   过时。

另一方面,我成功调用了此代码,因此似乎问题不是与SQLServer的连接

lookups = DB.Database?.Lookups.Where(l=>l.companyid==DB.CompanyID).ToLookup(g => g.LookupTypeId) ;

那么什么不起作用?

更新

来自DB

SELECT *,
      [Location].ToString() as WKT
  FROM [WorkReport]

Id  TypeID  ProximityId lineID  Location    WKT
178 6   2   7   0xE6100000010C8743DC9D754E4A40EB4B08A5400102C0  POINT (-2.25061158114976 52.6129643750674)
179 4   2   7   0xE6100000010CC4A6BF62F7504A40F9ACC89EB70602C0  POINT (-2.25327991533197 52.6325496135519)
180 7   2   7   0xE6100000010CAFC1F420EF624A40D795D41A58F301C0  POINT (-2.24382039033183 52.7729226298428)
181 7   3   7   0xE6100000010C988B36673E654A40E049A63A0BEA01C0  POINT (-2.23927923030827 52.7909668938002)
182 6   2   7   0xE6100000010CF3D11F539F8B4A4028430DF623DE02C0  POINT (-2.35846702793096 53.0907997041103)
183 8   2   8   0xE6100000010C82B9B41004534A40F97B9728ECDEF8BF  POINT (-1.55442443710467 52.6485615618176)
184 4   2   6   0xE6100000010C8A8A301567434A409AFAF6A6232BFEBF  POINT (-1.88553204746828 52.5265833365457)
185 9   2   4   0xE6100000010CBB7D019FD8404A40BD903C1DCA5902C0  POINT (-2.29384253350335 52.5066107518464)
186 8   2   4   0xE6100000010CF2EDF4D773134A406773A2484D9907C0  POINT (-2.94985443826447 52.1519727655358)
187 6   1   4   0xE6100000010C381064A1F6F849408310A651BCD10CC0  POINT (-3.60240997112311 51.94502656351)
188 2   3   4   0xE6100000010CD3FCB73E6AF3494087D7B17DB7950EC0  POINT (-3.82310388754826 51.9016798399331)
189 2   1   4   0xE6100000010C44BB08BD5EED4940C320C2BF4A9610C0  POINT (-4.14676952001918 51.8544536869654)
190 6   2   4   0xE6100000010C0124660902D8494019DDE9B866BC13C0  POINT (-4.93398560454741 51.6875621556028)
191 1   2   4   0xE6100000010CF135C7CD4DDD494082104C75780714C0  POINT (-5.00729544903527 51.7289368841847)

2 个答案:

答案 0 :(得分:0)

在调用Math.Round()时尝试将纬度和经度转换为(双精度):

var existing =( from r in DB.Database.Entities.OfType<DBWorkReport>()
          where Math.Round((double)r.Location.Latitude ?? 0, 6) == Math.Round(latitude, 6)
          && Math.Round((double)r.Location.Longitude ?? 0, 6) == Math.Round(longitude, 6)
          && r.WorkType.Description == type
          select r).FirstOrDefault();

确保'经度'和'纬度'也是'double'类型。

答案 1 :(得分:0)

Visual Studio突出显示的代码实际上与错误无关,它是早期的代码部分,它使用GDAL库重新投影North和East的引用,代码本身正在工作,但该库的一些东西显然导致错误,因为它停止了第二次我删除了该代码

using (OSGeo.OSR.SpatialReference inSpatialRef = new OSGeo.OSR.SpatialReference(""))
using (OSGeo.OSR.SpatialReference outSpatialRef = new OSGeo.OSR.SpatialReference(""))
{
    inSpatialRef.ImportFromEPSG(form);
    outSpatialRef.ImportFromEPSG(to);

    using (OSGeo.OSR.CoordinateTransformation coordTransform = new OSGeo.OSR.CoordinateTransformation(inSpatialRef, outSpatialRef))
    {
        coordTransform.TransformPoint(cord);
    }
}
return cord;

这表明问题出在作为GDAL包的一部分提供的osr_csharp.dll中