WPF AutomationPeer.Initialize periodically throws NullReferenceException

I have a WCF service that starts a WPF application to take screenshots.

In 95% of cases, everything works fine. But sometimes I get a TypeInitializeException when I call the myWindow.Show method .

An internal exception ( NullReferenceException ) occurred in the static Initialize method of the AutomationPeer class (PresentationCore.dll).

Full stack trace:

An unhandled exception of type 'System.TypeInitializationException' occurred in PresentationCore.dll

More information: An initializer of type "System.Windows.Automation.Peers.AutomationPeer" threw an exception.
at System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper (IInputElement newFocus) at System.Windows.Input.KeyboardDevice.ChangeFocus (DependencyObject focus, Int32 timestamp) at System.Windows.Input.FeyboardDevice , Boolean askNew, Boolean forceToNullIfFailed) at System.Windows.Input.KeyboardDevice.Focus (IInputElement element) at System.Windows.Interop.HwndKeyboardInputProvider.OnSetFocus (IntPtr hwnd) at System.Windows.Interop.Hwndage message WindowMessage, IntPtr wParam, IntPtr lParam, Boolean & handled) in System.Windows.Interop.HwndSource.InputFilterMessage (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & Intra.H. , 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 (Object delegate method, object arguments, int32 numArgs, catchHandler delegate) in System.Windows.Threading.Dispatcher.LegacyInvokeImpl (DispatcherPriority priority, TimeSpan timeout, delegate method, object arguments, Int32 numArgs) in MS.Win32.HwndSubclass.SubclassWinter hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)TryCatchWhen (Source object, delegate method, object arguments, int32 numArgs, catchHandler delegate) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl (DispatcherPriority priority, TimeSpan timeout, delegate method, object arguments, Int32 numArgs) at MS.Win32. HwndSubclass.SubclassWndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)TryCatchWhen (Source object, delegate method, object arguments, int32 numArgs, catchHandler delegate) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl (DispatcherPriority priority, TimeSpan timeout, delegate method, object arguments, Int32 numArgs) at MS.Win32. HwndSubclass.SubclassWndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

================= Internal Exception: [NullReferenceException] at System.Windows.Automation.Peers.AutomationPeer.Initialize () at System.Windows.Automation.Peers.AutomationPeer..cctor ()

I also found a workaround, but it doesn't work: http://blogs.msdn.com/b/jpvsblog/archive/2015/03/19/automationpeer-initialize-nre.aspx . The same exception occurs on this line:

 WindowAutomationPeer peer = new WindowAutomationPeer(m_wnd); 

      

+3
c # windows .net wpf wcf


source to share


No one has answered this question yet

Check out similar questions:

1877
What is a NullReferenceException and how do I fix it?
21
How to debug a binding in WPF
nine
Insufficient quota to process this -WPF command
2
WPF app crashes when going into standby
1
The specified Visual is not a descendant of this Visual Exception
1
Shared memory overflow
0
InvalidOperationException thrown when the ribbon is clicked
0
NullReferenceException when binding a property to a button in the Xceed Datagrid
0
Loading dll from resources fails
0
Multiple module opening and closing using Prism crashes app



All Articles
Loading...
X
Show
Funny
Dev
Pics