我有运行WPF应用程序的WCF服务来生成一些屏幕截图。
95%的情况下一切正常。 但有时当我调用 myWindow.Show 方法时,我会得到 TypeInitializeException 。
内部异常( NullReferenceException )发生在 AutomationPeer 类(PresentationCore.dll)的静态方法初始化中。
完整堆栈跟踪:
“System.TypeInitializationException”类型的未处理异常 发生在PresentationCore.dll
其他信息:Инициализатортипа “System.Windows.Automation.Peers.AutomationPeer”выдалисключение。
在 System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(IInputElement newFocus)in System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject的 焦点,Int32时间戳) System.Windows.Input.KeyboardDevice.Focus(DependencyObject焦点, Boolean askOld,Boolean askNew,Boolean forceToNullIfFailed)in System.Windows.Input.KeyboardDevice.Focus(IInputElement元素)中 System.Windows.Interop.HwndKeyboardInputProvider.OnSetFocus(IntPtr的 hwnd)in System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr的 hwnd,WindowMessage消息,IntPtr wParam,IntPtr lParam,Boolean& 处理) System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&处理) MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam, IntPtr lParam,Boolean&处理) MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)in System.Windows.Threading.ExceptionWrapper.InternalRealCall(代表 回调,对象args,Int32 numArgs)in MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象 source,Delegate方法,Object args,Int32 numArgs,Delegate catchHandler)in System.Windows.Threading.Dispatcher.LegacyInvokeImpl(的DispatcherPriority 优先级,TimeSpan超时,委托方法,对象args,Int32 numArgs)вMS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam)=================内部异常:[NullReferenceException异常]在System.Windows.Automation.Peers.AutomationPeer.Initialize()中 System.Windows.Automation.Peers.AutomationPeer..cctor()
我还找到了一种解决方法,但它不起作用:http://blogs.msdn.com/b/jpvsblog/archive/2015/03/19/automationpeer-initialize-nre.aspx。 此行中出现相同的异常:
WindowAutomationPeer peer = new WindowAutomationPeer(m_wnd);