我们正在开发一个WPF应用程序,该应用程序使用System.AddIn框架来托管显示其他WPF内容的加载项。一切似乎都运行良好,但一夜之间,应用程序抛出了以下NullReferenceException:
Message: Error : Object reference not set to an instance of an object. StackTrace : at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers) at System.AddIn.Pipeline.AddInHwndSourceWrapper.TranslateAccelerator(MSG msg, ModifierKeys modifiers) at MS.Internal.Controls.AddInHost.System.Windows.Interop.IKeyboardInputSink.TranslateAccelerator(MSG& msg, ModifierKeys modifiers) at System.Windows.Interop.HwndHost.OnKeyUp(KeyEventArgs e) at System.Windows.UIElement.OnKeyUpThunk(Object sender, KeyEventArgs e) at System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 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(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey) at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled) at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers) at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled) at System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled) at System.Windows.Interop.ThreadMessageEventHandler.Invoke(MSG& msg, Boolean& handled) at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run()
正如您所看到的,我们的代码都没有在堆栈跟踪中,所以我没有任何地方可以解决任何问题。有人对可能的解决方法有任何想法吗?
感谢您的帮助!
答案 0 :(得分:1)
我相信您需要关注的第一件事是更改Visual Studio中的设置。我有很多问题,必须手动告诉Visual Studio打破NullReferenceException。进行此调整后,IDE将实际抛出错误,您可以调试代码。来自VS 2008的帮助:
在抛出异常时中断执行 在“调试”菜单上,单击“例外”。
在“例外”对话框中,为整个例外类别选择“投掷”,例如“公共语言运行时例外”。
-OR -
展开一类异常的节点,例如,公共语言运行时异常,并为该类别中的特定异常选择“投掷”。
答案 1 :(得分:1)
此外,Steve Massing的上述答案可能有助于禁用“Just My Code”选项,启用“启用源服务器支持”选项并设置调试符号以打入并调试框架代码,
听起来比听起来容易,遵循这三个步骤
红线未选中,绿线检查并设置如下所示的符号
(来源:gangleri.net)
(来源:gangleri.net)