<legacyCorruptedStateExceptionsPolicy > 元素<legacyCorruptedStateExceptionsPolicy> Element

指定公共语言运行时是否允许托管的代码捕获访问冲突和其他损坏的状态异常。Specifies whether the common language runtime allows managed code to catch access violations and other corrupted state exceptions.

<configuration><configuration>
<运行时 ><runtime>
<legacyCorruptedStateExceptionsPolicy><legacyCorruptedStateExceptionsPolicy>

语法Syntax

<legacyCorruptedStateExceptionsPolicy enabled="true|false"/>  

特性和元素Attributes and Elements

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

特性Attributes

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

指定应用程序将捕获损坏状态异常失败,例如,访问冲突。Specifies that the application will catch corrupting state exception failures such as access violations.

enabled 特性enabled Attribute

Value 描述Description
false 应用程序将不会捕获损坏状态异常失败,例如,访问冲突。The application will not catch corrupting state exception failures such as access violations. 这是默认设置。This is the default.
true 应用程序将捕获损坏状态异常失败,例如,访问冲突。The application will catch corrupting state exception failures such as access violations.

子元素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 assembly binding and garbage collection.

备注Remarks

在.NET Framework 版本 3.5 及更早版本中,公共语言运行时允许托管的代码来捕获损坏的进程状态已引发的异常。In the .NET Framework version 3.5 and earlier, the common language runtime allowed managed code to catch exceptions that were raised by corrupted process states. 访问冲突是异常的这种类型的示例。An access violation is an example of this type of exception.

从.NET Framework 4 开始,托管的代码不能再捕获这些类型中的异常的catch块。Starting with the .NET Framework 4, managed code no longer catches these types of exceptions in catch blocks. 但是,您可以覆盖此更改并维护两种方式损坏的状态异常的处理:However, you can override this change and maintain the handling of corrupted state exceptions in two ways:

  • 设置<legacyCorruptedStateExceptionsPolicy>元素的enabled属性为trueSet the <legacyCorruptedStateExceptionsPolicy> element's enabled attribute to true. 此配置设置适用,并会影响所有方法。This configuration setting is applied processwide and affects all methods.

-or-

此配置元素是仅适用于.NET Framework 4 及更高版本。This configuration element is available only in the .NET Framework 4 and later.

示例Example

下面的示例演示如何指定应用程序应恢复为.NET Framework 4 之前, 的行为和捕获所有损坏状态异常失败。The following example shows how to specify that the application should revert to the behavior before the .NET Framework 4, and catch all corrupting state exception failures.

<configuration>  
   <runtime>  
      <legacyCorruptedStateExceptionsPolicy enabled="true" />  
   </runtime>  
</configuration>  

请参阅See also