Skip to content

Latest commit

 

History

History
72 lines (54 loc) · 2.97 KB

illegalprepareconstrainedregion-mda.md

File metadata and controls

72 lines (54 loc) · 2.97 KB
title description ms.date helpviewer_keywords ms.assetid
illegalPrepareConstrainedRegion MDA
Review the illegalPrepareConstrainedRegion managed debugging assistant, which is invoked if a PrepareConstrainedRegions call isn't followed by a try statement.
03/30/2017
PrepareConstrainedRegions method
managed debugging assistants (MDAs), illegal PrepareConstrainedRegions
try/catch exception handling, managed debugging assistants
IllegalPrepareConstrainedRegions MDA
MDAs (managed debugging assistants), illegal PrepareConstrainedRegions
2f9b5031-f910-4e01-a196-f89eab313eaf

illegalPrepareConstrainedRegion MDA

The illegalPrepareConstrainedRegion managed debugging assistant (MDA) is activated when a xref:System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions%2A?displayProperty=nameWithType 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.

Symptoms

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.

Cause

The preparation pattern for a CER is not followed correctly. This is an error event. The xref:System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions%2A 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.

Resolution

Ensure that the call to xref:System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions%2A happens immediately before the try statement.

Effect on the Runtime

This MDA has no effect on the CLR.

Output

The MDA displays the name of the method calling the xref:System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions%2A method, the MSIL offset, and a message indicating the call does not immediately precede the beginning of the try block.

Configuration

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

Example

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

void MethodWithInvalidPCR()  
{  
    RuntimeHelpers.PrepareConstrainedRegions();  
    Object o = new Object();  
    try  
    {}  
    finally  
    {}  
}  

See also