简体   繁体   English

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

[英]VS2012 XAML designer throws NullReferenceException, yet program still compiles and functions as expected

I have a page that is now showing in the XAML designer as throwing a NullReferenceException , where prior to making a couple of changes it didn't. 我有一个页面现在在XAML设计器中显示为抛出NullReferenceException ,而在进行一些未更改的地方。 The changes I made between not seeing the designer error and it appearing were: adding a couple of collapsed checkboxes to a StackPanel and making a couple of elements' visibility bound to their checked status. 我在看不到设计器错误和它出现之间所做的更改是:在StackPanel添加几个折叠的复选框,并使几个元素的可见性绑定到其选中状态。 Additionally, I created handlers for their checked and unchecked events. 另外,我为它们的选中和未选中事件创建了处理程序。 I have removed these changes (or at least I'm sure I have, but I'm still combing back over it) and the error still persists. 我已经删除了这些更改(或者至少我确定有,但是我仍在梳理一下),并且错误仍然存​​在。

My initial thoughts were that I had declared the checkboxes in the wrong order in the XAML code, but moving these did not remove the error, so I decided tried removing the changes to get it back to how it was pre-error, as noted above. 我最初的想法是,我在XAML代码中以错误的顺序声明了这些复选框,但是移动这些复选框并不能消除错误,因此我决定尝试删除所做的更改以使其恢复为错误前的状态,如上所述。 。 No dice. 没有骰子。

What I don't get about it, is the program still compiles fine and behaves exactly as I expected it to after making the changes (and always did). 我没有得到的是,程序在进行更改后(而且总是这样做)仍然可以正常编译并且表现出与我期望的完全相同的行为。 Further, the error being underlined in the XAML text editor is the Page declaration rather than the elements where I was playing around (and including loading the page that is throwing the exception) 此外,在XAML文本编辑器中强调的错误是Page声明,而不是我正在玩的元素(包括加载引发异常的页面)

I'm quite inexperienced at programming, so I wanted to know; 我对编程没有经验,所以我想知道。 A) is there a method I should be following to track this error down given it's not 'breaking' the compiler and is not throwing an error during debug. A)有没有一种方法可以跟踪该错误,因为它不会“破坏”编译器并且在调试过程中不会引发错误。 B) Given that the program still behaves as expected, how safe is it to continue without rooting out the cause? B)鉴于程序仍然可以按预期方式运行,在没有根源的情况下继续执行该程序有多安全?

(EDITED FROM HERE) Error Message: (从此处编辑)错误消息:

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)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM