<AppContextSwitchOverrides> 元素<AppContextSwitchOverrides> element

定义 AppContext 类使用的一个或多个开关,用于提供新功能的选择退出机制。Defines one or more switches used by the AppContext class to provide an opt-out mechanism for new functionality.

<configuration>
  <runtime>
    <AppContextSwitchOverrides>

语法Syntax

<AppContextSwitchOverrides value="name1=value1[[;name2=value2];...]" />

特性和元素Attributes and Elements

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

特性Attributes

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

定义一个或多个开关名称及其关联的布尔值。Defines one or more switch names and their associated Boolean values.

值特性value Attribute

Value 描述Description
"名称 = 值""name=value" 预定义的开关名称及其值 (truefalse) 。A predefined switch name along with its value (true or false). 多个开关名称/值对由分号分隔 ( ";") 。Multiple switch name/value pairs are separated by semicolons (";"). 有关 .NET Framework 支持的预定义开关名称的列表,请参阅 "备注" 部分。For a list of predefined switch names supported by the .NET Framework, see the Remarks section.

子元素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

从 .NET Framework 4.6 开始, <AppContextSwitchOverrides> 配置文件中的元素允许 API 的调用方确定其应用是否可以利用新功能或保持与以前版本的库的兼容性。Starting with .NET Framework 4.6, the <AppContextSwitchOverrides> element in a configuration file allows callers of an API to determine whether their app can take advantage of new functionality or preserve compatibility with previous versions of a library. 例如,如果 API 的行为在两个版本的库中发生了更改,则 <AppContextSwitchOverrides> 元素允许该 api 的调用方在支持新功能的库版本上选择禁用新行为。For example, if the behavior of an API has changed between two versions of a library, the <AppContextSwitchOverrides> element allows callers of that API to opt out of the new behavior on versions of the library that support the new functionality. 对于在 .NET Framework 中调用 Api 的应用程序, <AppContextSwitchOverrides> 如果应用程序在包含该功能的 .NET Framework 版本上运行,则该元素还可以允许其应用定位于 .NET Framework 早期版本的调用方选择新的功能。For apps that call APIs in the .NET Framework, the <AppContextSwitchOverrides> element can also allow callers whose apps target an earlier version of the .NET Framework to opt into new functionality if their app is running on a version of the .NET Framework that includes that functionality.

value元素的属性 <AppContextSwitchOverrides> 包含一个字符串,该字符串由一个或多个以分号分隔的名称/值对组成。The value attribute of the <AppContextSwitchOverrides> element consists of a single string that consists of one or more semicolon-delimited name/value pairs. 每个名称都标识一个兼容性开关,其对应的值为布尔值 (truefalse) ,指示是否设置了该开关。Each name identifies a compatibility switch, and its corresponding value is a Boolean (true or false) that indicates whether the switch is set. 默认情况下,开关是 false ,库提供新功能。By default, the switch is false, and libraries provide the new functionality. 如果开关设置 (为,则它们仅提供以前的功能,其值为 true) 。They only provide the previous functionality if the switch is set (that is, its value is true). 这允许库为现有 API 提供新行为,同时允许依赖于先前行为的调用方选择不使用新功能。This allows libraries to provide new behavior for an existing API while allowing callers who depend on the previous behavior to opt out of the new functionality.

.NET Framework 支持以下开关:.NET Framework supports the following switches:

交换机名称Switch name 描述Description 已引入Introduced
Switch.MS.Internal.
DoNotApplyLayoutRoundingToMarginsAndBorderThickness
控制 Windows Presentation Foundation 是否对控件布局使用旧算法。Controls whether Windows Presentation Foundation uses legacy a algorithm for control layout. 有关详细信息,请参阅缓解:WPF 布局For more information, see Mitigation: WPF Layout. .NET Framework 4.6.NET Framework 4.6
Switch.MS.Internal.
UseSha1AsDefaultHashAlgorithmForDigitalSignatures
控制 PackageDigitalSignatureManager 用于为包的部分签名的默认算法是 SHA1 还是 SHA256。Controls whether the default algorithm used for signing parts of a package by PackageDigitalSignatureManager is SHA1 or SHA256.
由于与 SHA1 冲突,Microsoft 建议使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.
.NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.Activities.
UseMD5CryptoServiceProviderForWFDebugger
如果设置为 false ,则允许在启用 FIPS 时通过 Visual Studio 调试基于 XAML 的工作流项目。When set to false, allows debugging of XAML-based workflow projects with Visual Studio when FIPS is enabled. 如果没有此 NullReferenceException 方法,则会在对 system.exception 程序集中的方法的调用中引发。Without it, a NullReferenceException is thrown in calls to methods in the System.Activities assembly. .NET Framework 4.7.NET Framework 4.7
Switch.System.Activities.
UseMD5ForWFDebugger
控制调试器中工作流实例的校验和是否使用 MD5 或 SHA1。Controls whether the checksum for a workflow instance in the debugger uses MD5 or SHA1. .NET Framework 4.7.NET Framework 4.7
Switch.System.Activities.
UseSHA1HashForDebuggerSymbols
控制工作流校验和是否哈希使用 .NET Framework 4.7 () 中引入为默认值的 SHA1 算法 true ,或是否使用默认 SHA256 算法,该算法在 .NET Framework 4.8 () 中引入为默认值 falseControls whether workflow checksum hashing uses the SHA1 algorithm introduced as the default in .NET Framework 4.7 (true), or whether it uses the default SHA256 algorithm introduced as the default in .NET Framework 4.8 (false).
由于与 SHA1 冲突,Microsoft 建议使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.
.NET Framework 4.8.NET Framework 4.8
Switch.System.Diagnostics.
IgnorePortablePDBsInStackTraces
控制在使用便携式 Pdb 时,堆栈跟踪是否获得,可以包括源文件和行信息。Controls whether stack traces obtain when using portable PDBs can include source file and line information. false 包括源文件和行信息;否则为 truefalse to include source file and line information; otherwise, true. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Drawing.
DontSupportPngFramesInIcons
控制 Icon.ToBitmap 方法在 Icon 对象具有 PNG 帧时是否引发异常。Controls whether the Icon.ToBitmap method throws an exception when an Icon object has PNG frames. 有关详细信息,请参阅缓解:图标对象中的 PNG 帧For more information, see Mitigation: PNG Frames in Icon Objects. .NET Framework 4.6.NET Framework 4.6
Switch.System.Drawing.Text.
DoNotRemoveGdiFontsResourcesFromFontCollection
确定 System.Drawing.Text.PrivateFontCollection 通过方法将对象添加到集合时是否正确释放对象 PrivateFontCollection.AddFontFile(String)Determines whether System.Drawing.Text.PrivateFontCollection objects are properly disposed when added to the collection by the PrivateFontCollection.AddFontFile(String) method. true 若要保留旧行为,则为;处理 false 所有专用字体对象。true to maintain the legacy behavior; false to dispose of all private font objects. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Drawing.Printing.
OptimizePrintPreview
控制是否为 PrintPreviewDialog 网络打印机优化的性能。Controls whether the performance of the PrintPreviewDialog is optimized for network printers. 有关详细信息,请参阅 PrintPreviewDialog 控件概述For more information, see PrintPreviewDialog control overview. .NET Framework 4.6.NET Framework 4.6
Switch.System.Globalization.EnforceJapaneseEraYearRanges 控制是否强制执行日本历纪元的年份范围检查。Controls whether year range checks for Japanese calendar eras are enforced. true 若要强制执行年份范围检查并 false 禁用它们 (默认行为) 。true to enforce year range checks, and false to disable them (the default behavior). 有关详细信息,请参阅使用 日历For more information, see Working with calendars. .NET Framework 4.6.NET Framework 4.6
Switch.System.Globalization.EnforceLegacyJapaneseDateParsing 控制在分析操作中是否仅将 "1" 识别为日本历时代的第一年。Controls whether only "1" is recognized as the first year of a Japanese calendar era in parsing operations. true 仅识别 "1"; false 若要识别 "1" 或 Gannen (默认行为) 。true to recognize only "1"; false to recognize either "1" or Gannen (the default behavior). 有关详细信息,请参阅使用 日历For more information, see Working with calendars. .NET Framework 4.6.NET Framework 4.6
Switch.System.Globalization.FormatJapaneseFirstYearAsANumber 控制日本历时代的第一年在格式设置操作中是否表示为 "1" 或 Gannen。Controls whether the first year of a Japanese calendar era is represented as "1" or Gannen in formatting operations. true 将纪元的第一年的格式设置为 "1"; false 若要将其设置为 Gannen (默认行为) 。true to format the era's first year as "1"; false to format it as Gannen (the default behavior). 有关详细信息,请参阅使用 日历For more information, see Working with calendars. .NET Framework 4.6.NET Framework 4.6
Switch.System.Globalization.NoAsyncCurrentCulture 控制异步操作是否不从调用线程的上下文中流动。Controls whether asynchronous operations do not flow from the calling thread's context. 有关详细信息,请参阅 跨任务的 CurrentCulture 和 CurrentUICulture 流For more information, see CurrentCulture and CurrentUICulture flow across tasks. .NET Framework 4.6.NET Framework 4.6
Switch.System.IdentityModel.
DisableMultipleDNSEntriesInSANCertificate
控制方法是否 X509CertificateClaimSet.FindClaims 尝试仅将声明类型与最后一个 DNS 条目进行匹配。Controls whether the X509CertificateClaimSet.FindClaims method attempts to match the claim type only with the last DNS entry. 有关详细信息,请参阅缓解:X509CertificateClaimSet.FindClaims 方法For more information, see Mitigation: X509CertificateClaimSet.FindClaims Method. .NET Framework 4.6.1.NET Framework 4.6.1
Switch.System.IdentityModel.
EnableCachedEmptyDefaultAuthorizationContext
控制是否允许 AuthorizationContext 返回可变对象。Controls whether to allow AuthorizationContext.Empty to return a mutable object. .NET Framework 4.6.NET Framework 4.6
Switch.System.IO.BlockLongPaths 控制超过 MAX_PATH 260 个字符的 (路径是否) 引发 PathTooLongExceptionControls whether paths longer than MAX_PATH (260 characters) throw a PathTooLongException. 有关详细信息,请参阅 长路径支持For more information, see Long Path Support. .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.IO.Compression.
DoNotUseNativeZipLibraryForDecompression
控制类是否使用本机操作系统例程进行解压缩 DeflateStreamControls whether native OS routines are used for decompression by the DeflateStream class. false 使用本机 Api; true 使用该 DeflateStream 实现。false to use native APIs; true to use the DeflateStream implementation. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.IO.Compression.ZipFile.
UseBackslash
使用反斜杠 ( " \ " ) 而不是正斜杠 ( "/" ) 作为属性中的路径分隔符 ZipArchiveEntry.FullNameUses the backslash ("\") rather than the forward slash ("/") as the path separator in the ZipArchiveEntry.FullName property. 有关详细信息,请参阅 缓解: ZipArchiveEntry 路径分隔符For more information, see Mitigation: ZipArchiveEntry.FullName Path Separator. .NET Framework 4.6.1.NET Framework 4.6.1
Switch.System.IO.Ports.
DoNotCatchSerialStreamThreadExceptions
控制在用流创建的后台线程上引发的操作系统异常是否 SerialPort 终止进程。Controls whether operating system exceptions that are thrown on background threads created with SerialPort streams terminate the process. .NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.IO.
UseLegacyPathHandling
控制是否使用旧版路径规范化并且和方法支持 URI 路径 Path.GetDirectoryName Path.GetPathRootControls whether legacy path normalization is used and URI paths are supported by the Path.GetDirectoryName and Path.GetPathRoot methods. 有关详细信息,请参阅 缓解:路径规范化缓解:路径冒号检查For more information, see Mitigation: Path Normalization and Mitigation: Path Colon Checks. .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.
MemberDescriptorEqualsReturnsFalseIfEquivalent
控制是否对相等性测试将 MemberDescriptor.Category 一个对象的属性与 MemberDescriptor.Description 第二个对象的属性进行比较。Controls whether a test for equality compares the MemberDescriptor.Category property of one object with the MemberDescriptor.Description property of the second object. 有关详细信息,请参阅 system.componentmodel.memberdescriptor.equals 的不正确实现For more information, see Incorrect implementation of MemberDescriptor.Equals. .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.Net.
DontCheckCertificateEKUs
禁用 (EKU) 对象标识符 (OID) 验证的证书增强型密钥用法。Disables certificate enhanced key usage (EKU) object identifier (OID) validation. 增强型密钥使用 (EKU) 扩展是指示使用密钥的应用程序的对象标识符 (OID) 的集合。An enhanced key usage (EKU) extension is a collection of object identifiers (OIDs) that indicate the applications that use the key. .NET Framework 4.6.NET Framework 4.6
Switch.System.Net.
DontEnableSchSendAuxRecord
禁用对 SSL/TLS 的 TLS 1.0 浏览器攻击 (BEAST) 通过禁用 SCH_SEND_AUX_RECORD 的使用来进行缓解。Disables TLS1.0 Browser Exploit Against SSL/TLS (BEAST) mitigation by disabling the use of SCH_SEND_AUX_RECORD. .NET Framework 4.6.NET Framework 4.6
Switch.System.Net.
DontEnableSchUseStrongCrypto
控制 System.Net.ServicePointManager 和类是否 System.Net.Security.SslStream 可以使用 SSL 3.0 协议。Controls whether the System.Net.ServicePointManager and System.Net.Security.SslStream classes can use the SSL 3.0 protocol. 有关详细信息,请参阅缓解:TLS 协议For more information, see Mitigation: TLS Protocols. .NET Framework 4.6.NET Framework 4.6
Switch.System.Net.
DontEnableSystemDefaultTlsVersions
禁用 SystemDefault TLS 版本恢复为默认的 Tls12、Tls11、Tls。Disables SystemDefault TLS versions reverting back to a default of Tls12, Tls11, Tls. .NET Framework 4.7.NET Framework 4.7
Switch.System.Net.
DontEnableTlsAlerts
禁用 System.net.security.sslstream TLS 服务器端警报。Disables SslStream TLS server-side Alerts. .NET Framework 4.7.NET Framework 4.7
Switch.System.Runtime.InteropServices.
DoNotMarshalOutByrefSafeArrayOnInvoke
控制 COM 互操作事件上的 ByRef SafeArray 参数是否封送回本机代码 (false) 或是否禁用了封送回本机代码 (true) 。Controls whether ByRef SafeArray parameters on COM interop events marshal back to native code (false) or whether marshaling back to native code is disabled (true). .NET Framework 4.8.NET Framework 4.8
Switch.System.Runtime.Serialization.
DoNotUseECMAScriptV6EscapeControlCharacter
控制 DataContractJsonSerializer 是否根据 ECMAScript V6 和 V8 标准序列化一些控制字符。Controls whether the DataContractJsonSerializer serializes some control characters based on the ECMAScript V6 and V8 standards. 有关详细信息,请参阅缓解:使用 DataContractJsonSerializer 对控制字符进行序列化For more information, see Mitigation: Serialization of Control Characters with the DataContractJsonSerializer .NET Framework 4.7.NET Framework 4.7
Switch.System.Runtime.Serialization.
DoNotUseTimeZoneInfo
控制是否 DataContractJsonSerializer 支持多个调整,或仅支持一个时区的单次调整。Controls whether the DataContractJsonSerializer supports multiple adjustments or only a single adjustment for a time zone. 如果为 true ,则它使用 TimeZoneInfo 类型来序列化和反序列化日期和时间数据; 否则,它使用 TimeZone 类型,该类型不支持多个调整规则。If true, it uses the TimeZoneInfo type to serialize and deserialize date and time data; otherwise, it uses the TimeZone type, which does not support multiple adjustment rules. .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.Runtime.Serialization.UseNewMaxArraySize 控制 System.Runtime.Serialization.ObjectManager 在对象序列化和反序列化过程中是否使用更大的数组大小。Controls whether System.Runtime.Serialization.ObjectManager uses a larger array size during object serialization and deserialization. 将此开关设置为可 true 通过类型(如)提高大型对象图的序列化和反序列化的性能 BinaryFormatterSet this switch to true to improve the performance of serialization and deserialization of large object graphs by types such as BinaryFormatter. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Security.ClaimsIdentity.
SetActorAsReferenceWhenCopyingClaimsIdentity
控制 ClaimsIdentity(IIdentity) 构造函数是否使用现有对象引用来设置新对象的 ClaimsIdentity.Actor 属性。Controls whether the ClaimsIdentity(IIdentity) constructor sets the new object's ClaimsIdentity.Actor property with an existing object reference. 有关详细信息,请参阅缓解:ClaimsIdentity 构造函数For more information, see Mitigation: ClaimsIdentity Constructor. .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.Security.Cryptography.
AesCryptoServiceProvider.DontCorrectlyResetDecryptor
控制尝试重用解密器是否会 AesCryptoServiceProvider 引发 CryptographicExceptionControls whether the attempt to reuse an AesCryptoServiceProvider decryptor throws a CryptographicException. 有关详细信息,请参阅 AesCryptoServiceProvider 解密器提供可重用的转换For more information, see AesCryptoServiceProvider decryptor provides a reusable transform. .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.Security.Cryptography.
DoNotAddrOfCspParentWindowHandle
控制 CspParameters system.security.cryptography.cspparameters.parentwindowhandle 属性的值是否为表示窗口句柄的内存位置的 IntPtr ,或者它是否是 HWND) (的窗口句柄。Controls whether the value of the CspParameters.ParentWindowHandle property is an IntPtr that represents the memory location of a window handle, or whether it is a window handle (an HWND). 有关详细信息,请参阅缓解:应向 CspParameters.ParentWindowHandle 分配 HWNDFor more information, see Mitigation: CspParameters.ParentWindowHandle Expects an HWND. .NET Framework 4.7.NET Framework 4.7
Switch.System.Security.Cryptography.
UseLegacyFipsThrow
控制在 FIPS 模式下使用托管加密类是引发 CryptographicException (true) 还是依赖于系统库 (false) 实现。Controls whether the use of managed cryptography classes in FIPS mode throws a CryptographicException (true) or relies on the implementation of system libraries (false). .NET Framework 4.8.NET Framework 4.8
Switch.System.Security.Cryptography.Pkcs.
UseInsecureHashAlgorithms
确定某些 SignedCMS 操作的默认值是 SHA1 还是 SHA256。Determines whether the default for some SignedCMS operations is SHA1 or SHA256.
由于与 SHA1 冲突,Microsoft 建议使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.
.NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.Security.Cryptography.X509Certificates.
ECDsaCertificateExtensions.UseLegacyPublicKeyReader
控制方法是否 ECDsaCertificateExtensions.GetECDsaPublicKey 正确地处理操作系统) (支持的所有已命名曲线 false ,或是否恢复到旧行为。Controls whether the ECDsaCertificateExtensions.GetECDsaPublicKey method correctly handles all named curves supported by the operating system (false) or reverts to legacy behavior. .NET Framework 4.8.NET Framework 4.8
Switch.System.Security.Cryptography.Xml.
UseInsecureHashAlgorithms
确定某些 SignedXML 操作的默认值是 SHA1 还是 SHA256。Determines whether the default for some SignedXML operations is SHA1 or SHA256.
由于与 SHA1 冲突,Microsoft 建议使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.
.NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.ServiceModel.
AllowUnsignedToHeader
确定 TransportWithMessageCredential 安全模式是否允许带有无符号 "to" 标头的消息。Determines whether the TransportWithMessageCredential security mode allows messages with an unsigned "to" header. 这是一个可选的开关。This is an opt-in switch. 有关详细信息,请参阅 .NET Framework 4.6.1 中的运行时更改For more information, see Runtime Changes in the .NET Framework 4.6.1. .NET Framework 4.6.1.NET Framework 4.6.1
Switch.System.ServiceModel.
DisableAddressHeaderCollectionValidation>
AddressHeaderCollection(IEnumerable<AddressHeader>) ArgumentException 如果其中一个元素为,则控制构造函数是否引发 nullControls whether the AddressHeaderCollection(IEnumerable<AddressHeader>) constructor throws an ArgumentException if one of the elements is null. .NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.ServiceModel.
DisableCngCertificates
确定尝试将 X509 证书与 CSG 密钥存储提供程序一起使用是否会引发异常。Determines whether the attempt to use X509 certificates with a CSG key storage provider throws an exception. 有关详细信息,请参阅 WCF 传输安全性支持使用 CNG 存储的证书For more information, see WCF transport security supports certificates stored using CNG. .NET Framework 4.6.1.NET Framework 4.6.1
Switch.System.ServiceModel.
DisableExplicitConnectionCloseHeader
将 HTTP 传输与自承载服务一起使用时,将此值设置为 true 会导致 WCF 忽略向 Connection: close 请求的响应标头添加标头的应用程序。When using the HTTP transport with a self-hosted service, setting this value to true causes WCF to ignore an application adding the Connection: close header to the response headers for a request. 如果将此值设置为, false 则可将 Connection: close 标头添加到响应标头,这会导致在发送响应后关闭请求套接字。Setting this value to false enables adding the Connection: close header to the response headers, which results in closing the request socket after a response has been sent. .NET Framework 4.6.NET Framework 4.6
Switch.System.ServiceModel.
DisableOperationContextAsyncFlow
处理因将可重入服务的实例限制为一次执行的单个线程而导致的死锁。Handles deadlocks that result from restricting instances of a re-entrant service to a single thread of execution at a time. .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.ServiceModel.
DisableUsingServicePointManagerSecurityProtocols
连同 Switch.System.Net.DontEnableSchUseStrongCrypto ,还决定 WCF 消息安全是否使用 tls 1.1 和 tls 1.2。Along with Switch.System.Net.DontEnableSchUseStrongCrypto, determines whether WCF message security uses TLS 1.1 and TLS 1.2. .NET Framework 4.7.NET Framework 4.7
Switch.System.ServiceModel.
DontEnableSystemDefaultTlsVersions
false 设置为允许操作系统选择协议的默认配置。A value of false sets the default configuration to allow the operating system to choose the protocol. 值为时, true 将默认值设置为最高可用协议。A value of true sets the default to the highest protocol available. (在以前的 framework 版本的服务分支中也可用) (Also available on servicing branch of previous framework versions) .NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.ServiceModel.
UseSha1InMsmqEncryptionAlgorithm
确定 WCF 中 MSMQ 消息的默认消息签名算法是 SHA1 还是 SHA256。Determines whether the default message signing algorithm for MSMQ messages in WCF is SHA1 or SHA256.
由于与 SHA1 冲突,Microsoft 建议使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.
.NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.ServiceModel.
UseSha1InPipeConnectionGetHashAlgorithm
控制 WCF 是使用 SHA1 还是 SHA256 哈希为命名管道生成随机名称。Controls whether WCF uses a SHA1 or a SHA256 hash to generate random names for named pipes.
由于与 SHA1 冲突,Microsoft 建议使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.
.NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.ServiceModel.Internals
IncludeNullExceptionMessageInETWTrace
控制在异常消息为 null 时是否引发 NullReferenceExceptionControls whether to throw a NullReferenceException when the exception message is null. .NET Framework 4.7.NET Framework 4.7
Switch.System.ServiceProcess.
DontThrowExceptionsOnStart
控制是否将在服务启动时引发的异常传播到方法的调用方 ServiceBase.RunControls whether exceptions thrown on service startup are propagated to the caller of the ServiceBase.Run method. .NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.Threading.UseNetCoreTimer 控制 Timer 实例是否利用大规模环境的性能改进。Controls whether Timer instances take advantage of performance improvements for high-scale environments. 如果 true 为,则启用性能改善; 如果 false (默认值) ,则会被禁用。If true, the performance improvements are enabled; if false (the default value), they are disabled. .NET Framework 4.8.NET Framework 4.8
Switch.System.Uri.
DontEnableStrictRFC3986ReservedCharacterSets
确定某些有时被解码的百分号编码字符现在是否一致地进行了编码。Determines whether certain percent-encoded characters that were sometimes decoded are now consistently left encoded. 如果 true 为,则对其进行解码; 否则为 falseIf true, they are decoded; otherwise, false. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Uri.
DontKeepUnicodeBidiFormattingCharacters
确定 Uri 中 Unicode 双向字符的处理。Determines the handling of Unicode bidirectional characters in URIs. true 从 Uri 中提取它们; false 保留并对其进行百分比编码。true to strip them from URIs; false to preserve and percent-encode them. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Windows.Controls.Grid.
StarDefinitionsCanExceedAvailableSpace
确定 Windows Presentation Foundation 将旧算法应用于 (true) 或新算法 (false) 将空间分配到 * 列。Determines whether Windows Presentation Foundation applies an old algorithm (true) or a new algorithm (false) in allocating space to *-columns. 有关详细信息,请参阅缓解:网格控件向 *-列分配空间For more information, see Mitigation: Grid Control's Space Allocation to Star-columns. .NET Framework 4.7.NET Framework 4.7
Switch.System.Windows.Controls.TabControl.
SelectionPropertiesCanLagBehindSelectionChangedEvent
控制选择器或选项卡控件是否始终在引发选择更改事件之前更新其选定值属性的值。Controls whether a selector or a tab control always updates the value of its selected value property before raising the selection changed event. .NET Framework 4.7.1.NET Framework 4.7.1
Switch.System.Windows.Controls.Text.
UseAdornerForTextboxSelectionRendering
确定基于非装饰器的选择呈现是否可用于 TextBox 和控件, PasswordBox 以防止封闭像素文本 (false) ,或者是否仅在装饰器层中呈现文本 (true) 。Determines whether non-Adorner-based selection rendering is available for the TextBox and PasswordBox controls to prevent occluded text (false), or whether text is rendered only in the Adorner layer (true). .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Windows.Data.Binding.
IListIndexerHidesCustomIndexer
控制是否使用错误地 (自定义 IList 索引器 true) 或正确 (false System.Windows.Data.Binding 类) 。Controls whether custom IList indexers are used incorrectly (true) or correctly (false) by the System.Windows.Data.Binding class. .NET Framework 4.8.NET Framework 4.8
Switch.System.Windows.DoNotScaleForDpiChanges 确定在每个系统上是否发生了 DPI 更改, (值为 false) 或每个监视器 (值 true) 。Determines whether DPI changes occur on a per-system (a value of false) or per-monitor basis (a value of true). .NET Framework 4.6.2.NET Framework 4.6.2
Switch.System.Windows.
DoNotUsePresentationDpiCapabilityTier2OrGreater
控制在按监视器识别模式下运行 WPF 时,是否对中的控件大小进行了改进 System.Windows.Interop.HwndHost , (true) 或启用了 (false) 。Controls whether improvements in sizing of controls in a System.Windows.Interop.HwndHost when WPF is run in per-monitor aware mode are disabled (true) or enabled (false). .NET Framework 4.8.NET Framework 4.8
Switch.System.Windows.Forms.
DomainUpDown.UseLegacyScrolling
确定在控件文本存在时开发人员是否需要专门处理 DomainUpDown.UpButton() 操作。Determines whether the developer needs to specially handle the DomainUpDown.UpButton() action when control text is present. true 若要处理 UpButton() 操作,则为; 如果 false DomainUpDown.UpButton() 和操作正确地同步,则为 DomainUpDown.DownButton()true to handle the UpButton() action; false for the DomainUpDown.UpButton() and DomainUpDown.DownButton() actions to be properly in sync. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Windows.Forms.
DontSupportReentrantFilterMessage
在代码中,允许自定义 IMessageFilter.PreFilterMessage 实现安全筛选消息,而不会在调用方法时引发异常 Application.FilterMessageOpts out of the code that allows a custom IMessageFilter.PreFilterMessage implementation to safely filter messages without throwing an exception when the Application.FilterMessage method is called. 有关详细信息,请参阅缓解:自定义 IMessageFilter.PreFilterMessage 实现For more information, see Mitigation: Custom IMessageFilter.PreFilterMessage Implementations. .NET Framework 4.6.1.NET Framework 4.6.1
Switch.System.Windows.Forms.
UseLegacyContextMenuStripSourceControlValue
确定 ContextMenuStrip.SourceControl 当用户通过嵌套控件打开菜单时,属性是否返回源代码管理 ToolStripMenuItemDetermines whether the ContextMenuStrip.SourceControl property returns the source control when the user opens the menu from a nested ToolStripMenuItem control. true 若要返回 null ,则为旧行为; false 返回源控件。true to return null, the legacy behavior; false to return the source control. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Windows.Forms.UseLegacyToolTipDisplay 控制是否禁用工具提示调用支持 (true) 或启用 (false) 。Controls whether tooltip invocation support is disabled (true) or enabled (false). 启用工具提示调用支持还需要由、和定义的旧版辅助功能, Switch.UseLegacyAccessibilityFeatures Switch.UseLegacyAccessibilityFeatures.2 Switch.UseLegacyAccessibilityFeatures.3 (设置为 false) 。Enabling tooltip invocation support also requires legacy accessibility features defined by Switch.UseLegacyAccessibilityFeatures, Switch.UseLegacyAccessibilityFeatures.2, and Switch.UseLegacyAccessibilityFeatures.3 all be disabled (set to false). .NET Framework 4.8.NET Framework 4.8
Switch.System.Windows.Input.Stylus.
EnablePointerSupport
确定是否 WM_POINTER 在 WPF 应用程序中启用了基于可选的触控/触笔堆栈。Determines whether an optional WM_POINTER-based touch/stylus stack is enabled in WPF applications. 有关详细信息,请参阅 缓解:基于指针的触控和触笔支持For more information, see Mitigation: Pointer-based Touch and Stylus Support .NET Framework 4.7.NET Framework 4.7
Switch.System.Windows.Markup.
DoNotUseSha256ForMarkupCompilerChecksumAlgorithm
确定用于校验和的默认哈希算法是 SHA256 (false) 还是 SHA1 (true) 。Determines whether the default hash algorithm used for checksums is SHA256 (false) or SHA1 (true).
由于与 SHA1 冲突,Microsoft 建议使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.
.NET Framework 4.7.2.NET Framework 4.7.2
Switch.System.Windows.Media.ImageSourceConverter.
OverrideExceptionWithNullReferenceException
控制是否引发旧的 NullReferenceException 而不是引发异常,更具体地指出异常的原因 (例如 DirectoryNotFoundExceptionsystem.io.filenotfoundexceptionControls whether a legacy NullReferenceException is thrown instead of the exception that more specifically indicates the cause of the exception (such as a DirectoryNotFoundException or a FileNotFoundException. 它旨在供依赖于处理 NullReferenceException的代码使用。It is intended for use by code that depends on handling the NullReferenceException. .NET Framework 4.7.NET Framework 4.7
Switch.System.Workflow.ComponentModel.
UseLegacyHashForXomlFileChecksum
控制工作流项目生成中的 XOML 文件的校验和哈希运算是使用 MD5 算法 (true) ,还是使用在 .NET Framework 4.8 中引入为默认值的 SHA256 算法。Controls whether checksum hashing of XOML files in workflow project builds use the MD5 algorithm (true), or whether they use the SHA256 algorithm introduced as the default in .NET Framework 4.8.
由于与 MD5 冲突,Microsoft 建议使用 SHA256。Due to collision problems with MD5, Microsoft recommends SHA256.
.NET Framework 4.8.NET Framework 4.8
Switch.System.Workflow.Runtime.
UseLegacyHashForSqlTrackingCacheKey
控制由 SqlTrackingService 哈希处理是否使用) 缓存字符串的 MD5 (算法 true ,或是否使用在 .NET Framework 4.8 中引入默认值的 SHA256 算法。Controls whether checksum hashing by the SqlTrackingService uses the MD5 algorithm (true) for cached strings, or whether it uses the SHA256 algorithm introduced as the default in .NET Framework 4.8.
由于与 MD5 冲突,Microsoft 建议使用 SHA256。Due to collision problems with MD5, Microsoft recommends SHA256.
.NET Framework 4.8.NET Framework 4.8
Switch.System.Workflow.Runtime.
UseLegacyHashForWorkflowDefinitionDispenserCacheKey
控制工作流运行时是否使用 MD5 算法 true 为缓存的工作流定义 () ,或者是否使用在 .NET Framework 4.8 中引入默认值的 SHA256 算法。Controls whether checksum hashing by the Workflow Runtime uses the MD5 algorithm (true) for cached workflow definitions, or whether it uses the SHA256 algorithm introduced as the default in .NET Framework 4.8.
由于与 MD5 冲突,Microsoft 建议使用 SHA256。Due to collision problems with MD5, Microsoft recommends SHA256.
.NET Framework 4.8.NET Framework 4.8
Switch.UseLegacyAccessibilityFeatures 控制是否启用或禁用从 .NET Framework 4.7.1 开始可用的辅助功能。Controls whether accessibility features available starting with .NET Framework 4.7.1 are enabled or disabled. .NET Framework 4.7.1.NET Framework 4.7.1
Switch.UseLegacyAccessibilityFeatures.2 控制是否启用 .NET Framework 4.7.2 中可用的辅助功能, (false) (true) 。Controls whether accessibility features available in .NET Framework 4.7.2 are enabled (false) or disabled (true). 如果 true 为,则 Switch.UseLegacyAccessibilityFeatures 必须同时 true 启用 .NET Framework 4.7.1 辅助功能。If true, Switch.UseLegacyAccessibilityFeatures must also be true to enable .NET Framework 4.7.1 accessibility features. .NET Framework 4.7.2.NET Framework 4.7.2
Switch.UseLegacyAccessibilityFeatures.3 控制是否 false) 或禁用 () (启用 .NET Framework 4.8 中引入的辅助功能 trueControls whether accessibility features introduced in .NET Framework 4.8 are enabled (false) or disabled (true). 如果 trueSwitch.UseLegacyAccessibilityFeaturesSwitch.UseLegacyAccessibilityFeatures.2 必须也为 trueIf true, Switch.UseLegacyAccessibilityFeatures and Switch.UseLegacyAccessibilityFeatures.2 must also be true. .NET Framework 4.8.NET Framework 4.8
Switch.UseLegacyToolTipDisplay 控制在用户将鼠标光标悬停在 () 的 WPF 控件上时是否显示工具提示 true ,或者是否在键盘焦点上以及通过键盘快捷键 (false 的默认行为) 显示工具提示。Controls whether tooltips are displayed when a user hovers the mouse cursor over a WPF control (true), or whether they are displayed both on keyboard focus and via keyboard shortcut key (false, the default behavior). 对于在 .NET Framework 4.8 上运行但面向以前版本的 .NET Framework 的应用程序,启用键盘焦点和快捷键支持要求 Switch.UseLegacyAccessibilityFeatures 将、 Switch.UseLegacyAccessibilityFeatures.2Switch.UseLegacyAccessibilityFeatures.3 均设置为 falseFor applications running on .NET Framework 4.8 but targeting previous versions of the .NET Framework, enabling both keyboard focus and shortcut key support requires that Switch.UseLegacyAccessibilityFeatures, Switch.UseLegacyAccessibilityFeatures.2, and Switch.UseLegacyAccessibilityFeatures.3 all be set to false. .NET Framework 4.8.NET Framework 4.8
Switch.System.Xml.
IgnoreEmptyKeySequences
控制 XSD 架构验证是否忽略复合键中的空键顺序。Controls whether empty key sequences in compound keys are ignored by XSD schema validation. 有关详细信息,请参阅 缓解: XML 架构验证For more information, see Mitigation: XML Schema Validation. .NET Framework 4.6.NET Framework 4.6

备注

AppContextSwitchOverrides你还可以通过在 c # 中调用 (,而不是将元素添加到应用程序配置文件 static 中 ) 或 Shared (Visual Basic) 方法中进行设置 AppContext.SetSwitchInstead of adding an AppContextSwitchOverrides element to an application configuration file, you can also set the switches programmatically by calling the static (in C#) or Shared (in Visual Basic) AppContext.SetSwitch method.

库开发人员还可以定义自定义开关,使调用方可以选择不更改其库的更高版本中引入的已更改功能。Library developers can also define custom switches to allow callers to opt out of changed functionality introduced in later versions of their libraries. 有关更多信息,请参见 AppContext 类。For more information, see the AppContext class.

ASP.NET 应用中的开关Switches in ASP.NET apps

可以通过将 <Add> 元素添加到 web.config 文件的部分,将 ASP.NET 应用程序配置为使用兼容性设置 <appSettings>You can configure an ASP.NET application to use compatibility settings by adding an <Add> element to the <appSettings> section of the web.config file.

下面的示例使用 <add> 元素将两个设置添加到 <appSettings> web.config 文件的部分:The following example uses the <add> element to add two settings to the <appSettings> section of a web.config file:

<appSettings>
  <add key="AppContext.SetSwitch:Switch.System.Globalization.NoAsyncCurrentCulture" value="true" />
  <add key="AppContext.SetSwitch:Switch.System.Uri.DontEnableStrictRFC3986ReservedCharacterSets" value="true" />
</appSettings>

示例Example

下面的示例使用 AppContextSwitchOverrides 元素定义单个应用程序兼容性开关, Switch.System.Globalization.NoAsyncCurrentCulture 该开关阻止区域性在异步方法调用中的线程之间流动。The following example uses the AppContextSwitchOverrides element to define a single application compatibility switch, Switch.System.Globalization.NoAsyncCurrentCulture, that prevents culture from flowing across threads in asynchronous method calls.

<configuration>
   <runtime>
      <AppContextSwitchOverrides value="Switch.System.Globalization.NoAsyncCurrentCulture=true" />
   </runtime>
</configuration>

下面的示例使用 AppContextSwitchOverrides 元素定义两个应用程序兼容性开关, Switch.System.Globalization.NoAsyncCurrentCultureSwitch.System.IO.BlockLongPathsThe following example uses the AppContextSwitchOverrides element to define two application compatibility switches, Switch.System.Globalization.NoAsyncCurrentCulture and Switch.System.IO.BlockLongPaths. 分号将两个名称/值对隔开。A semicolon separates the two name/value pairs.

<configuration>
    <runtime>
       <AppContextSwitchOverrides
          value="Switch.System.Globalization.NoAsyncCurrentCulture=true;Switch.System.IO.BlockLongPaths=true" />
    </runtime>
</configuration>

请参阅See also