Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COMException when I use a Popup in WPF

Tags:

.net

wpf

popup

I have a very annoying exception which freeze my application thrown by WPF, when the content of this popup seems to have to much element. In the output windows I see approximatively 50 times this exception.

'System.Runtime.InteropServices.COMException' occurred in UIAutomationProvider.dll

Then sometimes after the freeze I have this exception :

ContextSwitchDeadlock was detected Message: The CLR has been unable to transition from COM context 0x3bd0048 to COM context 0x3bd01b8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

I don't use any COM component in my code, does someone already had this problem ?

The Deadlock is detected by the debugger and doesn't have any stacktrace. The COM Exception stacktrace is :

{"An event was unable to invoke any of the subscribers (Exception from HRESULT: 0x80040201)"}

at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

at MS.Internal.Automation.UiaCoreProviderApi.UiaHostProviderFromHwnd(IntPtr hwnd)

When I call

popup.IsOpen = true
like image 642
Nicolas Dorier Avatar asked Sep 21 '09 11:09

Nicolas Dorier


3 Answers

A solution is to make Visibility="Collapsed" on the content of the popup, instead of closing the popup, but it's a bit hacky.

like image 53
Nicolas Dorier Avatar answered Oct 24 '22 12:10

Nicolas Dorier


I encountered the same issue. i guess it was related to a multitouch enabled dell monitor attached to my computer. when i a stopped the Tablet Input Service, the ComExceptions disappeared. maybe this is an option for you too.

like image 38
Joachim Kerschbaumer Avatar answered Oct 24 '22 12:10

Joachim Kerschbaumer


I fixed this problem by uninstalling a Wacom Pen and Touch tablet and disabling the Tablet Input Service. I encountered this issue with WPF Popups (TogglePopups, Comboboxes, etc) and Expanders.

like image 1
Guillaume Pinard Avatar answered Oct 24 '22 12:10

Guillaume Pinard