diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index cefb4c20fadc33..544cb5237914d6 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -28,7 +28,8 @@ Currently the identifiers `SYSLIB0001` through `SYSLIB0999` are carved out for o | __`SYSLIB0013`__ | Uri.EscapeUriString can corrupt the Uri string in some cases. Consider using Uri.EscapeDataString for query string components instead. | | __`SYSLIB0015`__ | DisablePrivateReflectionAttribute has no effect in .NET 6.0+ applications. | | __`SYSLIB0016`__ | Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations. | -| __`SYSLIB0017`__ | Strong name signing is not supported on this platform.| +| __`SYSLIB0017`__ | Strong name signing is not supported and throws PlatformNotSupportedException. | +| __`SYSLIB0018`__ | ReflectionOnly loading is not supported and throws PlatformNotSupportedException. | ### Analyzer warnings (`SYSLIB1001` - `SYSLIB1999`) | Diagnostic ID | Description | diff --git a/src/libraries/Common/src/System/Obsoletions.cs b/src/libraries/Common/src/System/Obsoletions.cs index 69070a348996bc..b9ec5493951436 100644 --- a/src/libraries/Common/src/System/Obsoletions.cs +++ b/src/libraries/Common/src/System/Obsoletions.cs @@ -55,7 +55,10 @@ internal static class Obsoletions internal const string GetContextInfoMessage = "Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations."; internal const string GetContextInfoDiagId = "SYSLIB0016"; - internal const string StrongNameKeyPairMessage = "Strong name signing is not supported on this platform."; + internal const string StrongNameKeyPairMessage = "Strong name signing is not supported and throws PlatformNotSupportedException."; internal const string StrongNameKeyPairDiagId = "SYSLIB0017"; + + internal const string ReflectionOnlyLoadingMessage = "ReflectionOnly loading is not supported and throws PlatformNotSupportedException."; + internal const string ReflectionOnlyLoadingDiagId = "SYSLIB0018"; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs index f7806ef8ddf8ac..ccc60df7818bcf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -372,13 +372,13 @@ public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, Assembly [RequiresUnreferencedCode("Types and members the loaded module depends on might be removed")] public virtual Module LoadModule(string moduleName, byte[]? rawModule, byte[]? rawSymbolStore) { throw NotImplemented.ByDesign; } - [Obsolete("ReflectionOnly loading is not supported on this platform.")] + [Obsolete(Obsoletions.ReflectionOnlyLoadingMessage, DiagnosticId = Obsoletions.ReflectionOnlyLoadingDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")] public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } - [Obsolete("ReflectionOnly loading is not supported on this platform.")] + [Obsolete(Obsoletions.ReflectionOnlyLoadingMessage, DiagnosticId = Obsoletions.ReflectionOnlyLoadingDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")] public static Assembly ReflectionOnlyLoad(string assemblyString) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } - [Obsolete("ReflectionOnly loading is not supported on this platform.")] + [Obsolete(Obsoletions.ReflectionOnlyLoadingMessage, DiagnosticId = Obsoletions.ReflectionOnlyLoadingDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")] public static Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs index 27ccbd4980d2c8..13cd39a6203d3d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs @@ -198,7 +198,7 @@ public AssemblyVersionCompatibility VersionCompatibility set => _versionCompatibility = value; } - [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId)] + [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public StrongNameKeyPair? KeyPair { get => throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs index 1a3be7eb595316..7ceaaebab1fb07 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs @@ -6,7 +6,7 @@ namespace System.Reflection { - [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId)] + [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public class StrongNameKeyPair : IDeserializationCallback, ISerializable { public StrongNameKeyPair(FileStream keyPairFile) => diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index 5c3e7f8547da3e..b04a56281833d3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.cs @@ -541,7 +541,7 @@ public override int GetHashCode() } public virtual bool Equals(Type? o) => o == null ? false : object.ReferenceEquals(this.UnderlyingSystemType, o.UnderlyingSystemType); - [Obsolete("ReflectionOnly loading is not supported on this platform.")] + [Obsolete(Obsoletions.ReflectionOnlyLoadingMessage, DiagnosticId = Obsoletions.ReflectionOnlyLoadingDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) => throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); public static Binder DefaultBinder diff --git a/src/libraries/System.Reflection/tests/AssemblyTests.cs b/src/libraries/System.Reflection/tests/AssemblyTests.cs index 5a97433306e411..fc2df64f794614 100644 --- a/src/libraries/System.Reflection/tests/AssemblyTests.cs +++ b/src/libraries/System.Reflection/tests/AssemblyTests.cs @@ -728,7 +728,7 @@ public void AssemblyLoadFromBytesWithSymbols() Assert.Equal(assembly.FullName, loadedAssembly.FullName); } -#pragma warning disable CS0618 // ReflectionOnly loading is not supported on this platform. +#pragma warning disable SYSLIB0018 // ReflectionOnly loading is not supported and throws PlatformNotSupportedException. [Fact] public void AssemblyReflectionOnlyLoadFromString() { @@ -751,7 +751,7 @@ public void AssemblyReflectionOnlyLoadFromNeg() Assert.Throws(() => Assembly.ReflectionOnlyLoad(string.Empty)); Assert.Throws(() => Assembly.ReflectionOnlyLoad((byte[])null)); } -#pragma warning restore CS0618 +#pragma warning restore SYSLIB0018 public static IEnumerable GetModules_TestData() { diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 6655ea065f32e2..033100384850a7 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -4571,7 +4571,7 @@ protected Type() { } public virtual System.Type MakePointerType() { throw null; } public static bool operator ==(System.Type? left, System.Type? right) { throw null; } public static bool operator !=(System.Type? left, System.Type? right) { throw null; } - [System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")] + [System.ObsoleteAttribute("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0018", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) { throw null; } public override string ToString() { throw null; } } @@ -7945,13 +7945,13 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo public static System.Reflection.Assembly? LoadWithPartialName(string partialName) { throw null; } public static bool operator ==(System.Reflection.Assembly? left, System.Reflection.Assembly? right) { throw null; } public static bool operator !=(System.Reflection.Assembly? left, System.Reflection.Assembly? right) { throw null; } - [System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")] + [System.ObsoleteAttribute("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0018", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")] public static System.Reflection.Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw null; } - [System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")] + [System.ObsoleteAttribute("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0018", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")] public static System.Reflection.Assembly ReflectionOnlyLoad(string assemblyString) { throw null; } - [System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")] + [System.ObsoleteAttribute("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0018", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")] public static System.Reflection.Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw null; } public override string ToString() { throw null; } @@ -8071,7 +8071,7 @@ public AssemblyName(string assemblyName) { } public System.Reflection.AssemblyNameFlags Flags { get { throw null; } set { } } public string FullName { get { throw null; } } public System.Configuration.Assemblies.AssemblyHashAlgorithm HashAlgorithm { get { throw null; } set { } } - [System.ObsoleteAttribute("Strong name signing is not supported on this platform.", DiagnosticId = "SYSLIB0017")] + [System.ObsoleteAttribute("Strong name signing is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0017", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public System.Reflection.StrongNameKeyPair? KeyPair { get { throw null; } set { } } public string? Name { get { throw null; } set { } } public System.Reflection.ProcessorArchitecture ProcessorArchitecture { get { throw null; } set { } } @@ -8919,7 +8919,7 @@ public static partial class RuntimeReflectionExtensions public static System.Collections.Generic.IEnumerable GetRuntimeProperties([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicProperties | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] this System.Type type) { throw null; } public static System.Reflection.PropertyInfo? GetRuntimeProperty([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] this System.Type type, string name) { throw null; } } - [System.ObsoleteAttribute("Strong name signing is not supported on this platform.", DiagnosticId = "SYSLIB0017")] + [System.ObsoleteAttribute("Strong name signing is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0017", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public partial class StrongNameKeyPair : System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable { public StrongNameKeyPair(byte[] keyPairArray) { } diff --git a/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs index 022d52b63d7180..10cf716f583303 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs @@ -11,7 +11,7 @@ namespace System.Reflection.Tests { public class StrongNameKeyPairTests : FileCleanupTestBase { -#pragma warning disable SYSLIB0017 // Strong name signing is not supported on this platform. +#pragma warning disable SYSLIB0017 // Strong name signing is not supported and throws PlatformNotSupportedException. [Fact] public void Ctor_ByteArray_ThrowsPlatformNotSupportedException() { diff --git a/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs b/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs index 6c9196814ebb62..a7e21552fcd615 100644 --- a/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs +++ b/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs @@ -570,11 +570,11 @@ public void GetTypeCode_ValidType_ReturnsExpected(Type t, TypeCode typeCode) [Fact] public void ReflectionOnlyGetType() { -#pragma warning disable CS0618 // ReflectionOnly loading is not supported on this platform. +#pragma warning disable SYSLIB0018 // ReflectionOnly loading is not supported and throws PlatformNotSupportedException. Assert.Throws(() => Type.ReflectionOnlyGetType(null, true, false)); Assert.Throws(() => Type.ReflectionOnlyGetType("", true, true)); Assert.Throws(() => Type.ReflectionOnlyGetType("System.Tests.TypeTests", false, true)); -#pragma warning restore CS0618 +#pragma warning restore SYSLIB0018 } [Fact]