【问题标题】:NullReferenceException when hosting WPF in a System.AddIn在 System.AddIn 中托管 WPF 时出现 NullReferenceException
【发布时间】:2010-09-21 07:36:57
【问题描述】:

我们正在开发一个 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()

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

感谢您的帮助!

【问题讨论】:

  • 您可以添加有关重现步骤的信息吗?您在应用程序启动后键入了一个键吗?您的 XAML 是否在 IDE 中正确预览且没有错误?您是否添加了任何 InputGestures 或键盘/鼠标绑定/事件?

标签: .net wpf exception add-in


【解决方案1】:

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

抛出异常时中断执行 在“调试”菜单上,单击“例外”。

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

-或-

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

【讨论】:

    【解决方案2】:

    除了史蒂夫·马辛的上述回答之外,它可能有助于禁用“仅我的代码”选项,启用“启用源服务器支持”选项并设置调试符号以闯入和调试框架代码,

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

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


    (来源:gangleri.net

    (来源:gangleri.net

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多