<NetFx40_PInvokeStackResilience > 元素<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>\<configuration>\ <runtime>\<runtime>\ <NetFx40_PInvokeStackResilience><NetFx40_PInvokeStackResilience>

语法Syntax

<NetFx40_PInvokeStackResilience  enabled="1|0"/>

特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
enabled 必需的特性。Required attribute.

指定是否在运行时检测到不正确的平台调用声明和 32 位平台上,将自动修复在运行时堆栈。Specifies whether the runtime detects incorrect platform invoke declarations and automatically fixes the stack at run time on 32-bit platforms.

enabled 特性enabled Attribute

Value 描述Description
0 运行时使用的更快的互操作封送处理体系结构引入了在.NET Framework 4 中,不会检测和修复不正确的平台调用声明。The runtime uses the faster interop marshaling architecture introduced in the .NET Framework 4, which does not detect and fix incorrect platform invoke declarations. 这是默认设置。This is the default.
1 运行时使用的转换速度的检测和修复不正确的平台调用声明。The runtime uses slower transitions that detect and fix incorrect platform invoke declarations.

子元素Child Elements

无。None.

父元素Parent Elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有关运行时初始化选项的信息。Contains information about runtime initialization options.

备注Remarks

此元素可以交换更快地互操作封送处理运行时恢复能力对不正确的平台调用声明。This element enables you to trade faster interop marshaling for run-time resilience against incorrect platform invoke declarations.

从.NET Framework 4 开始,简化的互操作封送处理体系结构提供了从托管代码转换到非托管代码一显著的性能改进。Starting with the .NET Framework 4, a streamlined interop marshaling architecture provides a significant performance improvement for transitions from managed code to unmanaged code. 在早期版本的.NET Framework,封送处理层检测到不正确的平台调用在 32 位平台上的声明,并自动修复堆栈。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.

为了更加轻松地在开发过程中检测不正确的声明,改进 Visual Studio 调试体验。To make it easy to detect incorrect declarations during development, the Visual Studio debugging experience has been improved. PInvokeStackImbalance托管调试助手 (MDA) 通知你的应用程序运行带有附加调试程序时,您不正确的平台调用声明。The pInvokeStackImbalance managed debugging assistant (MDA) notifies you of incorrect platform invoke declarations when your application is running with the debugger attached.

为应用程序使用组件,则不能重新编译,和,具有不正确的平台调用声明,您可以使用其中的解决情况NetFx40_PInvokeStackResilience元素。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. 将此元素添加到应用程序配置文件与enabled="1"opts 到与早期版本的.NET Framework 中,转换速度为代价的行为的兼容性模式。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. 已针对.NET Framework 的早期版本编译的程序集自动选择加入此兼容性模式,并且不需要此元素。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.

示例Example

下面的示例演示如何对不正确的增强恢复能力选择使用平台调用声明应用程序之间的转换速度为代价托管和非托管代码。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.

<configuration>
   <runtime>
      <NetFx40_PInvokeStackResilience enabled="1"/>
   </runtime>
</configuration>

请参阅See also