VS2012 XAML设计器抛出NullReferenceException,但程序仍然按预期编译和运行

时间:2014-02-12 01:26:27

标签: c# wpf xaml visual-studio-2012

我有一个页面现在在XAML设计器中显示为抛出NullReferenceException,在进行一些更改之前它没有。我在看不到设计器错误和出现之间所做的更改是:向StackPanel添加几个折叠的复选框,并使一些元素的可见性与其检查状态绑定。此外,我为其已检查和未检查的事件创建了处理程序。我已经删除了这些更改(或者至少我确定我已经删除了,但我仍然要对它进行梳理)并且错误仍然存​​在。

我最初的想法是我在XAML代码中以错误的顺序声明了复选框,但是移动它们并没有删除错误,因此我决定尝试删除更改以将其恢复为错误之前的状态,如上所述。没有骰子。

我还没有得到它,程序仍然编译得很好,并且在进行更改之后的行为完全符合我的预期(并且始终如此)。此外,XAML文本编辑器中的下划线错误是Page声明,而不是我正在玩的元素(包括加载抛出异常的页面)

我对编程很缺乏经验,所以我想知道; A)是否有一个我应该遵循的方法来跟踪这个错误,因为它没有“破坏”编译器并且在调试期间没有抛出错误。 B)鉴于程序仍然按预期运行,在没有根除原因的情况下继续运行有多安全?

(从此处编辑)错误消息:

NullReferenceException: Object reference not set to an instance of an object.
at PersonalArmyBuilder.WHFB8TH_Upgrader.ResetListBinding()
   at PersonalArmyBuilder.WHFB8TH_Upgrader.rdoItem_Checked(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.RadioButton.OnChecked(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ToggleButton.OnIsCheckedChanged(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.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.Primitives.ToggleButton.set_IsChecked(Nullable`1 value)
   at PersonalArmyBuilder.WHFB8TH_Upgrader.SetRadioButtonInitialStatus()
   at PersonalArmyBuilder.WHFB8TH_Upgrader.UserControl_Loaded(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
   at System.Windows.Interop.HwndTarget.OnResize()
   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(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)

1 个答案:

答案 0 :(得分:0)

刚刚通过继续执行其他任务发现了这个问题 - 事实证明我试图在其加载事件期间在usercontrol上运行一个方法,并且它指的是尚未实例化的对象。