我正在與一個奇怪的NullReferenceException發生衝突,它顯然是從ItemAutomationPeer類的GetNameCore()函數中觸發的。來自PresentationFramework.dll的NullReferenceException
該例外的細節如下,但真正有趣的方面是,它不會發生在我的開發計算機運行Windows 7,或我們測試過的其他Windows 7計算機上。它只發生在我的Windows 8 Pro測試機器上。
嘗試在WPF DataGrid控件中編輯單元格時引發異常。
我一直試圖追蹤它整天沒有成功。我嘗試使用Visual Studio遠程調試進程並逐步完成代碼,但沒有任何用戶代碼似乎觸發異常。這顯然是由PresentationFramework.Dll中的一系列事件執行的,異常只是通過AppDomain冒泡並最終導致應用程序崩潰。
如果有人能想到任何可能導致這種情況的方法或解決方法,那真的會有所幫助。
Exception Type: System.NullReferenceException
Exception Message: Object reference not set to an instance of an object.
Method Information: System.String GetNameCore()
Exception Source: PresentationFramework
Stack Trace
at System.Windows.Automation.Peers.ItemAutomationPeer.GetNameCore()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.ContextLayoutManager.fireAutomationEvents()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(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.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
當你說這種情況的Windows 8測試機上,是建立在同一臺機器上或應用程序Windows-8機器?或者它是建立在W7上,並剛從Windows-8執行?認爲在操作系統的操作系統之間有很多dll之間的錯誤匹配,並且需要一些引用在本地複製,以便在W7機器上構建時在Windows-8上運行。嘗試從Windows-8構建它,看看問題是否仍然存在。你可能會看到一個編譯錯誤,或者在完成後得到一些innerException細節,這可能表明哪個dll導致了不匹配(類似Aero對Aero2等) – Viv 2013-04-27 06:38:34
這是一個有趣的想法。我沒有裝有VS的Windows 8機器,所以我現在無法測試這個假設。但是,您可能會對框架略有不同。 – 2013-04-27 19:05:12