在我的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