在我的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));
}
如何在OnPropertyChanged事件中发布代码?没有看到代码,我们不能告诉你任何事情。我们不介意读者。 – 2014-10-08 13:57:01
什么是VerifyProperty?它可以处理空值或不正确的值吗? – OmegaMan 2014-10-08 14:37:25