我有WCF服务运行WPF应用程序生成一些截图。
在95%的情况下,一切正常。 但有时我调用myWindow.Show方法时,会得到TypeInitializeException 。
AutomationPeer类(PresentationCore.dll)的静态方法Initialize中发生内部exception( NullReferenceException )。
全堆栈跟踪:
PresentationCore.dll中发生未处理的“System.TypeInitializationException”types的exception
其他信息:Инициализатортипа“System.Windows.Automation.Peers.AutomationPeer”выдалисключение。
在System.Windows.Input.KeyboardDevice.Focus(DependencyObject焦点,布尔askOld,System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject焦点,Int32时间戳))System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(IInputElement newFocus)在System.Windows.Input.KeyboardDevice.Focus(IInputElement元素)在System.Windows.Interop.HwndKeyboardInputProvider.OnSetFocus(IntPtr hwnd)在System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr hwnd,WindowMessage消息)布尔askNew,布尔forceToNullIfFailed) (IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,布尔&处理)中的IntPtr wParam,IntPtr wParam,IntPtr lParam,布尔值和处理)IntPtr hwnd,Int32 msg ,IntPtr wParam,IntPtr lParam,布尔&处理)在System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托callback,对象 (System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority,TimeSpan timeout,Delegate)中的MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate method,Object args,Int32 numArgs,Delegate catchHandler)方法,对象args,Int32 numArgs)MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam)=================内部exception:System.Windows.Automation.Peers.AutomationPeer..cctor中System.Windows.Automation.Peers.AutomationPeer.Initialize()中的[NullReferenceException] ()
我也find了解决方法,但它不起作用: http : //blogs.msdn.com/b/jpvsblog/archive/2015/03/19/automationpeer-initialize-nre.aspx 。 这一行发生同样的exception:
WindowAutomationPeer peer = new WindowAutomationPeer(m_wnd);