[英]NullReferenceException when hosting WPF in a System.AddIn
我们正在开发一个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()
正如您所看到的,我们的代码都不在堆栈跟踪中,因此我没有任何地方可以解决任何问题。 有人对可能的解决方法有任何想法吗?
谢谢您的帮助!
我相信您需要关注的第一件事是更改Visual Studio中的设置。 我有很多问题,必须手动告诉Visual Studio打破NullReferenceException。 进行此调整后,IDE将实际抛出错误,您可以调试代码。 从VS 2008帮助:
在抛出异常时中断执行在“调试”菜单上,单击“例外”。
在“例外”对话框中,为整个例外类别选择“投掷”,例如“公共语言运行时例外”。
-要么-
展开一个例外类别的节点,例如,Common Language Runtime Exceptions,并为该类别中的特定异常选择Thrown。
此外,Steve Massing的上述答案可能有助于禁用“Just My Code”选项,启用“启用源服务器支持”选项并设置调试符号以便打入并调试框架代码,
它听起来比听起来容易,遵循这三个方向
红线未选中,绿线检查并设置如下符号
(来源: gangleri.net )
(来源: gangleri.net )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.