<legacyCorruptedStateExceptionsPolicy> 元素<legacyCorruptedStateExceptionsPolicy> Element

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



<legacyCorruptedStateExceptionsPolicy enabled="true|false"/>  

特性和元素Attributes and Elements

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


属性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


父元素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.


在 .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 开始,托管代码不再在块中捕获这些类型的异常 catchStarting 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. 此配置设置将应用 processwide 并影响所有方法。This configuration setting is applied processwide and affects all methods.


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


下面的示例演示如何指定应用程序应恢复到 .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.

      <legacyCorruptedStateExceptionsPolicy enabled="true" />  

另请参阅See also