【发布时间】:2013-04-21 04:14:01
【问题描述】:
我正在处理一个奇怪的 NullReferenceException,它显然是由 ItemAutomationPeer 类的 GetNameCore() 函数触发的。
该异常的详细信息如下,但真正有趣的是它不会发生在我运行 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 构建它,看看问题是否仍然存在。完成后您可能会看到编译错误或获得一些内部异常详细信息,这可能表明哪个 dll 导致了不匹配(例如 Aero 与 Aero2 等)
-
这是一个有趣的想法。我没有带 VS 的 Windows 8 机器,所以我现在无法测试这个假设。但是,您可能会注意到框架略有不同。