This documentation is archived and is not being maintained.

<NetFx40_PInvokeStackResilience> Element

Specifies whether the runtime automatically fixes incorrect platform invoke declarations at run time, at the cost of slower transitions between managed and unmanaged code.

<configuration> Element
  <runtime> Element
    <NetFx40_PInvokeStackResilience> Element
<NetFx40_PInvokeStackResilience  enabled="1|0"/>

The following sections describe attributes, child elements, and parent elements.





Required attribute.

Specifies whether the runtime detects incorrect platform invoke declarations and automatically fixes the stack at run time on 32-bit platforms.

enabled Attribute




The runtime uses the faster interop marshaling architecture introduced in the .NET Framework version 4, which does not detect and fix incorrect platform invoke declarations. This is the default.


The runtime uses slower transitions that detect and fix incorrect platform invoke declarations.

Child Elements


Parent Elements




The root element in every configuration file used by the common language runtime and .NET Framework applications.


Contains information about runtime initialization options.

This element enables you to trade faster interop marshaling for run-time resilience against incorrect platform invoke declarations.

Starting with the .NET Framework 4, a streamlined interop marshaling architecture provides a significant performance improvement for transitions from managed code to unmanaged code. In earlier versions of the .NET Framework, the marshaling layer detected incorrect platform invoke declarations on 32-bit platforms and automatically fixed the stack. The new marshaling architecture eliminates this step. As a result, transitions are very fast, but an incorrect platform invoke declaration can cause a program failure.

To make it easy to detect incorrect declarations during development, the Visual Studio debugging experience has been improved. The pInvokeStackImbalance managed debugging assistant (MDA) notifies you of incorrect platform invoke declarations when your application is running with the debugger attached.

To address scenarios where your application uses components that you cannot recompile, and that have incorrect platform invoke declarations, you can use the NetFx40_PInvokeStackResilience element. Adding this element to your application configuration file with enabled="1" opts into a compatibility mode with the behavior of earlier versions of the .NET Framework, at the cost of slower transitions. Assemblies that have been compiled against earlier versions of the .NET Framework are automatically opted into this compatibility mode, and do not need this element.

Configuration File

This element can be used only in the application configuration file.

The following example shows how to opt into increased resilience against incorrect platform invoke declarations for an application, at the cost of slower transitions between managed and unmanaged code.

      <NetFx40_PInvokeStackResilience enabled="1"/>