3

我们正在开发一个 WPF 应用程序,该应用程序使用 System.AddIn 框架来托管显示其他 WPF 内容的加载项。一切似乎都运行良好,但一夜之间,应用程序抛出了以下 NullReferenceException:

消息:错误:对象引用未设置为对象的实例。
StackTrace:在 System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG 和 msg,ModifierKeys 修饰符)
   在 System.AddIn.Pipeline.AddInHwndSourceWrapper.TranslateAccelerator(MSG 味精,ModifierKeys 修饰符)
   在 MS.Internal.Controls.AddInHost.System.Windows.Interop.IKeyboardInputSink.TranslateAccelerator(MSG& 味精,ModifierKeys 修饰符)
   在 System.Windows.Interop.HwndHost.OnKeyUp(KeyEventArgs e)
   在 System.Windows.UIElement.OnKeyUpThunk(对象发送者,KeyEventArgs e)
   在 System.Windows.Input.KeyEventArgs.InvokeEventHandler(委托 genericHandler,对象 genericTarget)
   在 System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)
   在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,RoutedEventArgs routedEventArgs)
   在 System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs args,布尔 reRaised)
   在 System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs 参数)
   在 System.Windows.UIElement.RaiseEvent(RoutedEventArgs 参数,布尔值信任)
   在 System.Windows.Input.InputManager.ProcessStagingArea()
   在 System.Windows.Input.InputManager.ProcessInput(InputEventArgs 输入)
   在 System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   在 System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd,InputMode 模式,Int32 时间戳,RawKeyboardActions 操作,Int32 扫描代码,布尔 isExtendedKey,布尔 isSystemKey,Int32 虚拟键)
   在 System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(味精和味精,布尔值&处理)
   在 System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(味精和味精,ModifierKeys 修饰符)
   在 System.Windows.Interop.HwndSource.OnPreprocessMessage(对象参数)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象参数,布尔 isSingleParameter)
   在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象 args,布尔 isSingleParameter,委托 catchHandler)
   在 System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority 优先级,TimeSpan 超时,委托方法,对象参数,布尔 isSingleParameter)
   在 System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority 优先级,委托方法,对象 arg)
   在 System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(味精和味精,布尔值&处理)
   在 System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& 味精,布尔值& 处理)
   在 System.Windows.Interop.ThreadMessageEventHandler.Invoke(MSG&味精,布尔&处理)
   在 System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(味精和味精)
   在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame 框架)
   在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame 框架)
   在 System.Windows.Threading.Dispatcher.Run()
   在 System.Windows.Application.RunInternal(窗口窗口)
   在 System.Windows.Application.Run(窗口窗口)
   在 System.Windows.Application.Run()

正如你所看到的,我们的代码都没有在堆栈跟踪中,所以我没有地方修复任何东西。有人对可能的解决方法有任何想法吗?

谢谢您的帮助!

4

2 回答 2

1

我相信您需要查看的第一件事是更改 Visual Studio 中的设置。我对此有很多问题,不得不手动告诉 Visual Studio 打破那个 NullReferenceException。进行此调整后,IDE 实际上会抛出错误,您可以调试代码。从 VS 2008 帮助:

在引发异常时中断执行 在“调试”菜单上,单击“异常”。

在“异常”对话框中,为整个异常类别选择“引发”,例如,公共语言运行时异常。

-或者-

展开异常类别的节点,例如公共语言运行时异常,然后为该类别中的特定异常选择抛出。

于 2008-11-12T05:14:28.883 回答
1

此外,Steve Massing 的上述回答可能有助于禁用“仅我的代码”选项,启用“启用源服务器支持”选项并设置调试符号以闯入和调试框架代码,

这比听起来容易,请按照以下 3 步说明进行操作

红线未选中,绿线选中并设置符号如下

替代文字
(来源:gangleri.net(来源:gangleri.net
替代文字

于 2008-12-04T22:02:56.713 回答