簡體   English   中英

在System.AddIn中托管WPF時出現NullReferenceException

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM