<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>
  <runtime>
    <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" "导入" 到兼容模式,并且具有较早版本的 .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