2012-01-23 27 views
5

Ứng dụng .NET 4 của tôi sử dụng TreeView WPF mà tôi đã tăng cường để bật điều hướng bàn phím và tải chậm, chẳng hạn. Vấn đề của tôi là, rất hiếm khi, ngoại lệ được hiển thị bên dưới được ném. Điều này đã xảy ra với tôi chỉ một lần trong những tháng phát triển, và tôi có báo cáo lỗi từ một số khách hàng cũng nhận được điều này một lần trong một thời gian. Thật hiếm khi tôi không thể thay đổi một cái gì đó, chơi xung quanh với ứng dụng trong một thời gian và biết nếu vấn đề đã biến mất hay không.Làm thế nào để gỡ lỗi NullReferenceException trong PresentationFramework?

Nhưng câu hỏi chính của tôi là: theo dõi ngăn xếp chỉ hiển thị mã Microsoft, không có gì từ tôi trong đó. Đây có phải là lỗi trong .NET/WPF không? Và có bất kỳ cơ hội để có được nguyên nhân gốc rễ?

Type: System.NullReferenceException 
Message: Object reference not set to an instance of an object. 
Source: PresentationFramework 
Stack trace: at System.Windows.Controls.ItemContainerGenerator.ContainerFromIndex(Int32 index) 
    at System.Windows.Controls.TreeViewItem.FindNextFocusableItem(Boolean walkIntoSubtree) 
    at System.Windows.Controls.TreeViewItem.InternalPredictFocus(FocusNavigationDirection direction) 
    at System.Windows.Controls.VirtualizingStackPanel.FocusChanged(KeyboardFocusChangedEventArgs e) 
    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
    at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
    at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) 
    at System.Windows.Input.InputManager.ProcessStagingArea() 
    at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp) 
    at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed) 
    at System.Windows.Input.KeyboardDevice.Focus(IInputElement element) 
    at System.Windows.UIElement.Focus() 
    at System.Windows.Controls.TreeViewItem.OnItemsChanged(NotifyCollectionChangedEventArgs e) 
    at System.Windows.Controls.ItemsControl.OnItemCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) 
    at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e) 
    at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) 
    at System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView view) 
    at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange) 
    at System.Windows.Data.BindingExpression.Activate(Object item) 
    at System.Windows.Data.BindingExpression.OnDataContextChanged(DependencyObject contextElement) 
    at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs) 
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) 
    at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) 
    at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.RemoveAll() 
    at System.Windows.Controls.VirtualizingStackPanel.ClearAllContainers(ItemsControl itemsControl) 
    at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.ClearContainerForItem(DependencyObject container, Object item) 
    at System.Windows.Controls.ItemContainerGenerator.UnlinkContainerFromItem(DependencyObject container, Object item) 
    at System.Windows.Controls.ItemContainerGenerator.Remove(GeneratorPosition position, Int32 count, Boolean isRecycling) 
    at System.Windows.Controls.VirtualizingStackPanel.CleanupRange(IList children, IItemContainerGenerator generator, Int32 startIndex, Int32 count) 
    at System.Windows.Controls.VirtualizingStackPanel.CleanupContainers(Int32 firstViewport, ItemsControl itemsControl) 
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.TreeViewItem.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.TreeViewItem.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.TreeViewItem.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.TreeViewItem.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.TreeViewItem.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.ContextLayoutManager.UpdateLayout() 
    at System.Windows.Interop.HwndSource.Process_WM_SIZE(UIElement rootUIElement, IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam) 
    at System.Windows.Interop.HwndSource.LayoutFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
Target: System.Windows.DependencyObject ContainerFromIndex(Int32) 
Inner exception message: 

Lưu ý: Tôi cũng có trên máy tính của mình, chạy Windows 7 x64 được vá đầy đủ.

Trả lời

4

Cá nhân tôi chưa bao giờ phát hiện ra lỗi trong WPF. Tuy nhiên, bước vào mã WPF đã thường xuyên cho phép tôi để theo dõi nguồn gốc của vấn đề trở lại bản thân mình.

Dưới đây là một số điều MSDN về cách kích hoạt nguồn Khung gỡ lỗi:

Liên kết với tất cả các phiên bản: https://msdn.microsoft.com/en-us/library/cc667410.aspx

+0

Cảm ơn, có vẻ thú vị! –

+2

Bạn đã liên kết với mô tả VS 2008. Đây là bài viết MSDN "Cách: Debug .NET Framework Source" cho VS 2010: http://msdn.microsoft.com/en-us/library/cc667410.aspx –

+0

Cảm ơn. Tôi sẽ cập nhật liên kết. –

Các vấn đề liên quan