Udostępnij za pośrednictwem


disconnectedContext MDA

The disconnectedContext managed debugging assistant (MDA) is activated when the CLR attempts to transition into a disconnected apartment or context while servicing a request concerning a COM object.

Symptoms

Calls made on a Runtime Callable Wrapper (RCW) are delivered to the underlying COM component in the current apartment or context instead of the one in which they exist. This can cause corruption and or data loss if the COM component is not multithreaded, as in the case of single-threaded apartment (STA) components. Alternatively, if the RCW is itself a proxy, the call might result in the throwing of a COMException with an HRESULT of RPC_E_WRONG_THREAD.

Cause

The OLE apartment or context has been shut down when the CLR attempts to transition into it. This is most commonly caused by STA apartments being shut down before all the COM components owned by the apartment were completely released This can occur as a result of an explicit call from user code on an RCW or while the CLR itself is manipulating the COM component, for example when the CLR is releasing the COM component when the associated RCW has been garbage collected.

Resolution

To avoid this problem, ensure the thread that owns the STA does not terminate before the application has finished with all the objects that live in the apartment. The same applies to contexts; ensure contexts are not shut down before the application is completely finished with any COM components that live inside the context.

Effect on the Runtime

This MDA has no effect on the CLR. It only reports data about the disconnected context.

Output

Reports the context cookie of the disconnected apartment or context.

Configuration

<mdaConfig>
  <assistants>
    <disconnectedContext enable="false" />
  </assistants>
</mdaConfig>

See Also

Concepts

Diagnosing Errors with Managed Debugging Assistants

Interop Marshaling Overview

Reference

MarshalAsAttribute

Other Resources

Interoperability