I have a problem with the OpenFileDialog from Windows Forms (it does not matter if I use is in a console application, win forms or wpf) (C#).
I have a small test project with a button that, when pressed, will ask the user to select an image (using OpenFileDialog) and send its path to a process method. The process method is in c++ native code and accessed using c++ cli (CLR). This method send a request to a web service and waits for the response (the web service is local, so the response is fast).
The problem is this: if I press the button 2 times (select an image + processing and after it's finished I process another image), the 3rd time the window will not show, it gets stuck at ShowDialog.
If I run it from WPF it gives me this error:
DisconnectedContext occurred Message: Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'd:\Project\WpfApplication1.vshost.exe'.
Additional information: Transition into COM context 0x1b09d5d0 for this RuntimeCallableWrapper failed with the following error: The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)). This is typically because the COM context 0x1b09d5d0 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else and cannot process the context transition. No proxy will be used to service the request on the COM component and calls will be made to the COM component directly. This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.
Any ideas how to solve this or what it means ?
I found the problem (it was not from the webservice communication): Somewhere in my native code I was uninitializing COM, but .NET UI needs COM to be up and running.
So all I had to do is remove the unitialization of COM from my native code.
User contributions licensed under CC BY-SA 3.0