代码之家  ›  专栏  ›  技术社区  ›  Abe Heidebrecht

在system.addin中托管wpf时出现nullreferenceexception

  •  3
  • Abe Heidebrecht  · 技术社区  · 16 年前

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

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

    谢谢你的帮助!

    2 回复  |  直到 5 年前
        1
  •  1
  •   Steve Massing    16 年前

    我相信您首先需要考虑的是在visual studio中更改设置。我在这方面有很多问题,必须手动告诉visual studio中断那个nullreferenceexception。一旦做出此调整,IDE将实际抛出错误,您可以调试您的代码。从VS 2008帮助:

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

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

    -或

    展开一类异常(例如,公共语言运行时异常)的节点,然后为该类别中的特定异常选择“引发”。

        2
  •  1
  •   Glorfindel DataWraith    5 年前

    此外,steve massing的上述回答可能有助于禁用“just my code”选项,启用“enable source server support”选项,并设置调试符号,以便闯入和调试框架代码,

    听上去容易多了,按照以下三个步骤操作

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

    alt text
    (来源: gangleri.net )
    alt text
    (来源: gangleri.net )