API 已过时并带有非默认诊断 ID
从 .NET 5 开始,某些 API 标记为已过时。 此中断性变更特定于标记为已过时并带有自定义诊断 ID 的 API。 取消默认过时诊断 ID(对于 C# 编译器,即为 CS0618),不会取消使用这些 API 时编译器生成的警告。
更改描述
在以前的 .NET 版本中,可以使用这些 API,而不会引发任何生成警告。 在 .NET 5 及更高版本中,使用这些 API 会生成编译时警告或错误,并显示自定义诊断 ID。 使用自定义诊断 ID 可单独取消某个过时警告,而不是取消所有过时警告。
下表列出了已过时 API 的自定义诊断 ID 及其相应的警告消息。
诊断 ID | 说明 | 严重性 |
---|---|---|
SYSLIB0001 | UTF-7 编码不安全,因此不应使用。 请考虑改用 UTF-8。 | 警告 |
SYSLIB0002 | PrincipalPermissionAttribute 不受运行时支持,不得使用。 | 错误 |
SYSLIB0003 | 运行时不支持或不接受代码访问安全性 (CAS)。 | 警告 |
SYSLIB0004 | 不支持受约束的执行区域 (CER) 功能。 | 警告 |
SYSLIB0005 | 不支持全局程序集缓存 (GAC)。 | 警告 |
SYSLIB0006 | Thread.Abort() 不受支持并会引发 PlatformNotSupportedException。 | 警告 |
SYSLIB0007 | 不支持此加密算法的默认实现。 | 警告 |
SYSLIB0008 | CreatePdbGenerator() API 不受支持并会引发 PlatformNotSupportedException。 | 警告 |
SYSLIB0009 | AuthenticationManager.Authenticate 和 AuthenticationManager.PreAuthenticate 方法都不受支持并会引发 PlatformNotSupportedException。 | 警告 |
SYSLIB0010 | 某些远程处理 API 不受支持并会引发 PlatformNotSupportedException。 | 警告 |
SYSLIB0011 | BinaryFormatter 序列化已过时,不应使用。 | 警告 |
SYSLIB0012 | 包含 Assembly.CodeBase 和 Assembly.EscapedCodeBase 只是为了实现 .NET Framework 兼容性。 请改用 Assembly.Location。 | 警告 |
引入的版本
.NET 5.0
建议操作
使用警告中提供的 URL 链接,遵循为每个诊断 ID 提供的特定指南。
不能使用过时类型或成员的标准诊断 ID 取消有关这些过时类型或成员的警告或错误;请改用自定义
SYSLIBxxxx
诊断 ID 值。
受影响的 API
SYSLIB0001
SYSLIB0002
SYSLIB0003
System.Security.Permissions
命名空间中的类:
- System.Security.Permissions.CodeAccessSecurityAttribute
- System.Security.Permissions.DataProtectionPermission
- System.Security.Permissions.DataProtectionPermissionAttribute
- System.Security.Permissions.EnvironmentPermission
- System.Security.Permissions.EnvironmentPermissionAttribute
- System.Security.Permissions.FileDialogPermission
- System.Security.Permissions.FileDialogPermissionAttribute
- System.Security.Permissions.FileIOPermission
- System.Security.Permissions.FileIOPermissionAttribute
- System.Security.Permissions.GacIdentityPermission
- System.Security.Permissions.GacIdentityPermissionAttribute
- System.Security.Permissions.HostProtectionAttribute
- System.Security.Permissions.IsolatedStorageFilePermission
- System.Security.Permissions.IsolatedStorageFilePermissionAttribute
- System.Security.Permissions.IsolatedStoragePermission
- System.Security.Permissions.IsolatedStoragePermissionAttribute
- System.Security.Permissions.KeyContainerPermission
- System.Security.Permissions.KeyContainerPermissionAccessEntry
- System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
- System.Security.Permissions.KeyContainerPermissionAccessEntryEnumerator
- System.Security.Permissions.KeyContainerPermissionAttribute
- System.Security.Permissions.MediaPermission
- System.Security.Permissions.MediaPermissionAttribute
- System.Security.Permissions.PermissionSetAttribute
- System.Security.Permissions.PrincipalPermission
- System.Security.Permissions.PrincipalPermissionAttribute
- System.Security.Permissions.PublisherIdentityPermission
- System.Security.Permissions.PublisherIdentityPermissionAttribute
- System.Security.Permissions.ReflectionPermission
- System.Security.Permissions.ReflectionPermissionAttribute
- System.Security.Permissions.RegistryPermission
- System.Security.Permissions.RegistryPermissionAttribute
- System.Security.Permissions.ResourcePermissionBase
- System.Security.Permissions.ResourcePermissionBaseEntry
- System.Security.Permissions.SecurityAttribute
- System.Security.Permissions.SecurityPermission
- System.Security.Permissions.SecurityPermissionAttribute
- System.Security.Permissions.SiteIdentityPermission
- System.Security.Permissions.SiteIdentityPermissionAttribute
- System.Security.Permissions.StorePermission
- System.Security.Permissions.StorePermissionAttribute
- System.Security.Permissions.StrongNameIdentityPermission
- System.Security.Permissions.StrongNameIdentityPermissionAttribute
- System.Security.Permissions.StrongNamePublicKeyBlob
- System.Security.Permissions.TypeDescriptorPermission
- System.Security.Permissions.TypeDescriptorPermissionAttribute
- System.Security.Permissions.UIPermission
- System.Security.Permissions.UIPermissionAttribute
- System.Security.Permissions.UrlIdentityPermission
- System.Security.Permissions.UrlIdentityPermissionAttribute
- System.Security.Permissions.WebBrowserPermission
- System.Security.Permissions.WebBrowserPermissionAttribute
- System.Security.Permissions.ZoneIdentityPermission
- System.Security.Permissions.ZoneIdentityPermissionAttribute
派生自 CodeAccessSecurityAttribute
的类:
- System.Configuration.ConfigurationPermissionAttribute
- System.Data.Common.DBDataPermissionAttribute
- System.Data.Odbc.OdbcPermissionAttribute
- System.Data.OleDb.OleDbPermissionAttribute
- System.Data.OracleClient.OraclePermissionAttribute
- System.Data.SqlClient.SqlClientPermissionAttribute
- System.Diagnostics.EventLogPermissionAttribute
- System.Diagnostics.PerformanceCounterPermissionAttribute
- System.DirectoryServices.DirectoryServicesPermissionAttribute
- System.Drawing.Printing.PrintingPermissionAttribute
- System.Net.DnsPermissionAttribute
- System.Net.SocketPermissionAttribute
- System.Net.WebPermissionAttribute
- System.Net.Mail.SmtpPermissionAttribute
- System.Net.NetworkInformation.NetworkInformationPermissionAttribute
- System.Net.PeerToPeer.PnrpPermissionAttribute
- System.Net.PeerToPeer.Collaboration.PeerCollaborationPermissionAttribute
- System.ServiceProcess.ServiceControllerPermissionAttribute
- System.Transactions.DistributedTransactionPermissionAttribute
- System.Web.AspNetHostingPermissionAttribute
接口:
- System.Security.Permissions.IUnrestrictedPermission
- System.Security.IPermission
- System.Security.IStackWalk
- System.Security.Policy.IIdentityPermissionFactory
实现 IStackWalk
的类:
实现 IPermission
的类:
派生自 CodeAccessPermission
的类:
- System.Configuration.ConfigurationPermission
- System.Data.Common.DBDataPermission
- System.Data.Odbc.OdbcPermission
- System.Data.OleDb.OleDbPermission
- System.Data.SqlClient.SqlClientPermission
- System.Data.OracleClient.OraclePermission
- System.Drawing.Printing.PrintingPermission
- System.Net.DnsPermission
- System.Net.SocketPermission
- System.Net.WebPermission
- System.Net.Mail.SmtpPermission
- System.Net.NetworkInformation.NetworkInformationPermission
- System.Net.PeerToPeer.PnrpPermission
- System.Net.PeerToPeer.Collaboration.PeerCollaborationPermission
- System.Transactions.DistributedTransactionPermission
- System.Web.AspNetHostingPermission
- System.Xaml.Permissions.XamlLoadPermission
派生自 ResourcePermissionBase
的类:
- System.Diagnostics.EventLogPermission
- System.Diagnostics.PerformanceCounterPermission
- System.DirectoryServices.DirectoryServicesPermission
- System.ServiceProcess.ServiceControllerPermission
System.Security.Permissions
命名空间中的枚举:
- System.Security.Permissions.DataProtectionPermissionFlags
- System.Security.Permissions.EnvironmentPermissionAccess
- System.Security.Permissions.FileDialogPermissionAccess
- System.Security.Permissions.FileIOPermissionAccess
- System.Security.Permissions.HostProtectionResource
- System.Security.Permissions.IsolatedStorageContainment
- System.Security.Permissions.KeyContainerPermissionFlags
- System.Security.Permissions.MediaPermissionAudio
- System.Security.Permissions.MediaPermissionImage
- System.Security.Permissions.MediaPermissionVideo
- System.Security.Permissions.PermissionState
- System.Security.Permissions.ReflectionPermissionFlag
- System.Security.Permissions.RegistryPermissionAccess
- System.Security.Permissions.SecurityAction
- System.Security.Permissions.SecurityPermissionFlag
- System.Security.Permissions.StorePermissionFlags
- System.Security.Permissions.TypeDescriptorPermissionFlags
- System.Security.Permissions.UIPermissionClipboard
- System.Security.Permissions.UIPermissionWindow
- System.Security.Permissions.WebBrowserPermissionLevel
依赖于代码访问安全类型的类和成员:
- System.AppDomain.ExecuteAssembly(String, String[], Byte[], AssemblyHashAlgorithm)
- System.AppDomain.PermissionSet
- System.Runtime.InteropServices.AllowReversePInvokeCallsAttribute
- System.Security.HostProtectionException
- System.Security.Policy.FileCodeGroup
- System.Security.Policy.StrongName
- System.Security.Policy.StrongNameMembershipCondition
- System.Security.Policy.ApplicationTrust.ApplicationTrust(PermissionSet, IEnumerable<StrongName>)
- System.Security.Policy.ApplicationTrust.FullTrustAssemblies
- System.Security.Policy.GacInstalled
- System.Security.Policy.PolicyStatement.PolicyStatement
- System.Security.Policy.PolicyLevel.AddNamedPermissionSet(NamedPermissionSet)
- System.Security.Policy.PolicyLevel.ChangeNamedPermissionSet(String, PermissionSet)
- System.Security.Policy.PolicyLevel.GetNamedPermissionSet(String)
- System.Security.Policy.PolicyLevel.RemoveNamedPermissionSet(String)
- PolicyLevel.RemoveNamedPermissionSet(NamedPermissionSet)
- System.Security.Policy.PolicyStatement.PermissionSet
- System.Security.Policy.Publisher
- System.Security.Policy.Site
- System.Security.Policy.Url
- System.Security.Policy.Zone
- System.Security.SecurityManager
SYSLIB0004
- RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(RuntimeHelpers+TryCode, RuntimeHelpers+CleanupCode, Object)
- RuntimeHelpers.PrepareConstrainedRegions()
- RuntimeHelpers.PrepareConstrainedRegionsNoOP()
- RuntimeHelpers.PrepareContractedDelegate(Delegate)
- RuntimeHelpers.ProbeForSufficientStack()
- System.Runtime.ConstrainedExecution.Cer
- System.Runtime.ConstrainedExecution.Consistency
- System.Runtime.ConstrainedExecution.PrePrepareMethodAttribute
- System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
SYSLIB0005
SYSLIB0006
SYSLIB0007
- System.Security.Cryptography.AsymmetricAlgorithm.Create()
- System.Security.Cryptography.HashAlgorithm.Create()
- System.Security.Cryptography.HMAC.Create()
- System.Security.Cryptography.KeyedHashAlgorithm.Create()
- System.Security.Cryptography.SymmetricAlgorithm.Create()
SYSLIB0008
SYSLIB0009
SYSLIB0010
SYSLIB0011
- System.Exception.SerializeObjectState
- BinaryFormatter.Serialize
- BinaryFormatter.Deserialize
- Formatter.Serialize(Stream, Object)
- Formatter.Deserialize(Stream)
- IFormatter.Serialize(Stream, Object)
- IFormatter.Deserialize(Stream)