Export (0) Print
Expand All

illegalPrepareConstrainedRegion MDA

The illegalPrepareConstrainedRegion managed debugging assistant (MDA) is activated when a RuntimeHelpers.PrepareConstrainedRegions method call does not immediately precede the try statement of the exception handler. This restriction is at the MSIL level, so it is permissible to have non-code-generating source between the call and the try, such as comments.

A constrained execution region (CER) that is never treated as such, but as a simple exception handling block (finally or catch). As a consequence, the region does not run in the event of an out-of-memory condition or a thread abort.

The preparation pattern for a CER is not followed correctly. This is an error event. The PrepareConstrainedRegions method call used to mark exception handlers as introducing a CER in their catch/finally/fault/filter blocks must be used immediately before the try statement.

Ensure that the call to PrepareConstrainedRegions happens immediately before the trystatement.

This MDA has no effect on the CLR.

The MDA displays the name of the method calling the PrepareConstrainedRegions method, the MSIL offset, and a message indicating the call does not immediately precede the beginning of the try block.

<mdaConfig>
  <assistants>
    <illegalPrepareConstrainedRegion/>
  </assistants>
</mdaConfig>

The following code example demonstrates the pattern that causes this MDA to be activated.

void MethodWithInvalidPCR()
{
    RuntimeHelpers.PrepareConstrainedRegions();
    Object o = new Object();
    try
    {
        …
    }
    finally
    {
        …
    }
}
Show:
© 2014 Microsoft