<NetFx40_PInvokeStackResilience> 項目<NetFx40_PInvokeStackResilience> Element

指定執行階段是否會在執行階段自動修復不正確的平台叫用宣告,即使這麼做會使 Managed 和 Unmanaged 程式碼之間的轉換變慢。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 Attribute

Value 描述Description
0 執行時間會使用 .NET Framework 4 中引進的更快 interop 封送處理架構,這不會偵測並修正不正確的平台叫用宣告。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

此元素可讓您針對執行時間復原,針對不正確的平台叫用宣告,進行更快速的 interop 封送處理。This element enables you to trade faster interop marshaling for run-time resilience against incorrect platform invoke declarations.

從 .NET Framework 4 開始,簡化的 interop 封送處理架構可大幅改善從 managed 程式碼轉換為非受控碼的效能。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 managed 偵錯工具(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

下列範例示範如何針對應用程式的不正確平台叫用宣告,選擇增加的復原能力,代價是 managed 和非受控碼之間的轉換速度較慢。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