2014-10-07 190 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垃圾如何收集仍在使用的对象?

相关问题