2014-10-07 189 views
-3

在我的WPF C#應用程序中,偶爾會出現錯誤:「異常的類型'System.ExecutionEngineException'被拋出」。該錯誤似乎發生在OnPropertyChanged事件的中間。WPF,類型'System.ExecutionEngineException'的異常被拋出

來自例外的信息: InnerException爲null。 Data is {System.Collections.EmptyReadOnlyDictionaryInternal}

我正在使用.Net 4.5.1。

任何人有任何想法會導致這種情況?

protected void OnPropertyChanged(string propName) 
    { 
     VerifyProperty(propName); 

     PropertyChangedEventHandler handler = PropertyChanged; 

     if (handler != null) 
     { 
      try 
      { 
       handler(this, new PropertyChangedEventArgs(propName)); 
      } 
      catch (Exception) 
      { 
      } 
     } 
    } 

在PropertyChangedEventArgs調用過程中出現異常。

這是驗證屬性。

[Conditional("DEBUG")] 
    private void VerifyProperty(string property) 
    { 
     Type t = this.GetType(); 

     System.Reflection.PropertyInfo info = t.GetProperty(property); 

     if (info == null) 
      throw new ArgumentException(string.Format("Property \"{0}\" does not exist in type {1}!", property, t.Name)); 
    } 
+0

如何在OnPropertyChanged事件中發佈代碼?沒有看到代碼,我們不能告訴你任何事情。我們不介意讀者。 – 2014-10-08 13:57:01

+0

什麼是VerifyProperty?它可以處理空值或不正確的值嗎? – OmegaMan 2014-10-08 14:37:25

回答

0

我發現一些引用可能導致System.ExecutionEngineException的垃圾回收問題。我還發現了幾個引發異常的.Net錯誤的引用。

在我們的代碼中,異常發生時正在更新的對象正在同時進行修改。修改是單個對象引用: project.ExtendedData = status.ProjectStatus; ExtendedData是發生異常時正在更新的屬性。

我修改了代碼,以便在修改對象時禁用更新。這解決了這個問題。在修復之前,我能夠在80%的時間內重現錯誤。

我不知道如何才能引用垃圾收集的對象。我認爲對象不應該被垃圾收集,直到沒有對象的引用。 CLR垃圾如何收集仍在使用的對象?

相關問題