WPF - Inside DispatcherUnhandledException处理程序,如何找到有问题的代码?

时间:2017-09-22 11:49:14

标签: c# wpf

我有一个WPF应用程序,它在不同的页面中有许多数据网格。我有时会看到引发InvalidOperationException。我既不能找到发生问题的代码位置,也不能重现问题。

[编辑]堆栈跟踪在我的代码中没有关于问题根源的信息 - 也就是说我想知道源代码中异常的来源在哪里?

例如,出现问题时,DispatcherUnhandledException中记录了以下堆栈跟踪:

  

System.InvalidOperationException:在AddNew或EditItem事务期间不允许'DeferRefresh'。          在System.Windows.Data.CollectionView.DeferRefresh()          在System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView视图)          在System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)          在System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)          在System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)          在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)          在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata metadata,EffectiveValueEntry oldEntry,EffectiveValueEntry& newEntry,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType)          在System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp,Boolean preserveCurrentValue)          在System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)          在System.Windows.Data.BindingExpression.TransferValue(Object newValue,Boolean isASubPropertyChange)          在MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k,ICollectionView collectionView,Object newValue,Boolean isASubPropertyChange)          在MS.Internal.Data.ClrBindingWorker.ScheduleTransferOperation(Object arg)          在MS.Internal.Data.DataBindEngine.ProcessCrossThreadRequests()          在System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,Int32 numArgs)          在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate方法,Object args,Int32 numArgs,Delegate catchHandler)

但是从上面的堆栈跟踪中,我无法弄清楚我的项目中的哪个代码片段导致了这个问题。有没有办法弄清楚导致这个异常的线程/方法?

0 个答案:

没有答案