2016-05-31 117 views
1

我運行這段代碼爲什麼我收到FatalExecutionEngineError

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 occurred HResult=-2146233082
Message=Exception of type 'System.ExecutionEngineException' was thrown. InnerException:

enter image description here

引述MSDN:

FatalExecutionEngineError: This type previously indicated an unspecified fatal error in the runtime. The runtime no longer raises this exception so this type is obsolete.

在另一一點上,我成功地調用這個代碼,所以它不似乎問題是連接到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) 
+0

也許'r.Location' null? – rene

+1

您是否檢查過內部異常的細節? –

+0

@rene添加內容的位置不存在空值 – MikeT

回答

0

Visual Studio突出顯示的代碼實際上與該錯誤無關,它是使用GDAL庫重新投影Long/Lat的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

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(); 

確保 '經度' 和'緯度'也是類型'雙'。

+0

這將是一個InvalidCastException,並且所有的long和lats已經是雙精度謝謝你嘗試 – MikeT

相關問題