具有非預設診斷識別碼的 API 淘汰
從 .NET 5 開始,某些 API 已標示為已淘汰。 這項中斷性變更專屬於已標示為已過時且「具有自訂診斷識別碼」的 API。 隱藏 C# 編譯器的預設淘汰診斷識別碼,也就是 CS0618,不會隱藏使用這些 API 時編譯器所產生的警告。
變更描述
在舊版 .NET 中,可以使用這些 API,且不會出現任何建置警告。 在 .NET 5 與更新版本中,使用這些 API 會產生具有自訂診斷識別碼的編譯時間警告或錯誤。 使用自訂診斷識別碼可讓您個別隱藏淘汰警告,而不是隱藏所有淘汰警告。
下表列出已淘汰 API 的自訂診斷識別碼及其對應的警告訊息。
診斷識別碼 | 描述 | 嚴重性 |
---|---|---|
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 連結來遵循針對每個診斷識別碼提供的特定指引。
使用淘汰類型或成員的標準診斷識別碼無法隱藏這些淘汰項目的警告或錯誤;請改用自訂
SYSLIBxxxx
診斷識別碼值。
受影響的 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)