Question

I am attempting to create an MMC snapin that among other things, will receive and display log events that are fired from my service. I have created the watcher and it fires correctly, but when I try to add nodes to my MmcListView, I am getting a COMException which says "COM object that has been separated from its underlying RCW cannot be used."

Here is the code in question:

private void LogEvent_EventArrived(object sender, EventArrivedEventArgs e)
{
    LogEvent logEvent = new LogEvent(e.NewEvent);
    if (SnapIn.InvokeRequired)
    {
        object[] args = new object[] { logEvent };
        SnapIn.Invoke(new ManagementAction(AddEvent), args);
    }
    else
        AddEvent(logEvent);
}

The LogEvent class is a simple class which does the work of converting the ManagmentBaseObject properties to type safe properties which are easily coded against. The AddEvent method does the actual work of adding the LogEvent object to the ResultNodes list of the MmcListView.

The Exception I mentioned is actually called on the SECOND event being fired, and seems to happen on the call to InvokeRequired. I have no idea what is actually going on here. Any ideas?

Was it helpful?

Solution

OK, this was incredibly stupid... but the reality was that the method I was calling via Invoke was throwing an exception, and it wasn't bubbling up as expected to the caller, and instead was showing as the weird COM exception. Once I cleared up the exception in the method I was calling via delegate, everything worked fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top