InvalidCastException: RPC_E_CANTCALLOUT_ININPUTSYNCCALL

I am creating a C # application that has a static class that initiates a COM class and handles some event handlers of another class that intercepts the keyboard. When I call a COM class method from a button event handler in my WPF window, this method works without issue, but when I call it in one of the event callbacks in my static class, it throws the following exception:

Unable to pass COM object of type BLAHBLAH to interface type 'BLAHBLAH. This operation failed because the QueryInterface request for the COM component for the interface with IID '{9DD6680B-3EDC-40DB-A771-E6FE4832E34A}' failed due to the following Error: Outgoing call could not be completed because the application is sending a synchronous call ... (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL)).

Could you please tell me what this exception means and how can I resolve it?

+1


source to share


2 answers


Wrap your code in a new thread:



Thread thread = new Thread(() =>
{
    ManagementObjectSearcher theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
    foreach (ManagementObject currentObject in theSearcher.Get())
    {
        Debug.WriteLine("Device present: " + currentObject);          
        ManagementObject theSerialNumberObjectQuery = new ManagementObject("Win32_PhysicalMedia.Tag='" + currentObject["DeviceID"] + "'");
        serial = theSerialNumberObjectQuery["SerialNumber"].ToString();
    }
});
thread.Start();
thread.Join(); //wait for the thread to finish

      

+1


source


Please refer to this KB http://support.microsoft.com/kb/198996 It looks like it is because of threads (maybe not user defined)



0


source







All Articles