From 0e685227310754fbe5ddcde28478ad666a3f252e Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 8 Apr 2021 10:36:15 -0700 Subject: [PATCH 1/9] Annotate unsupported APIs in .Net core as Obsolete - --- .../src/System/Reflection/Assembly.cs | 3 +++ .../src/System/Reflection/StrongNameKeyPair.cs | 2 ++ src/libraries/System.Private.CoreLib/src/System/Type.cs | 1 + src/libraries/System.Runtime/ref/System.Runtime.cs | 6 ++++++ 4 files changed, 12 insertions(+) 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 bd6dd45fb0b45e..fdf63a9d1f1e86 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -372,10 +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.")] [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.")] [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.")] [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/StrongNameKeyPair.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs index ee5ffafa706c44..3f3cb11ee72cdf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs @@ -29,9 +29,11 @@ public StrongNameKeyPair(byte[] keyPairArray) protected StrongNameKeyPair(SerializationInfo info, StreamingContext context) => throw new PlatformNotSupportedException(); + [Obsolete("Strong-name signing is not supported on this platform.")] public StrongNameKeyPair(string keyPairContainer) => throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); + [Obsolete("Strong-name signing is not supported on this platform.")] public byte[] PublicKey => throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index 6b01229d10274b..5c3e7f8547da3e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.cs @@ -541,6 +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.")] 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.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index a07dee6da547f0..385fb816af4055 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -4427,6 +4427,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.")] public static System.Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) { throw null; } public override string ToString() { throw null; } } @@ -7798,10 +7799,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.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.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.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; } @@ -8773,7 +8777,9 @@ public partial class StrongNameKeyPair : System.Runtime.Serialization.IDeseriali public StrongNameKeyPair(byte[] keyPairArray) { } public StrongNameKeyPair(System.IO.FileStream keyPairFile) { } protected StrongNameKeyPair(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } + [System.ObsoleteAttribute("Strong-name signing is not supported on this platform.")] public StrongNameKeyPair(string keyPairContainer) { } + [System.ObsoleteAttribute("Strong-name signing is not supported on this platform.")] public byte[] PublicKey { get { throw null; } } void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { } void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } From a6f1c58b1acdc32a994d53f79fbeb4a5ae509f1b Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 8 Apr 2021 11:53:59 -0700 Subject: [PATCH 2/9] Disable warning in test --- src/libraries/System.Reflection/tests/AssemblyTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Reflection/tests/AssemblyTests.cs b/src/libraries/System.Reflection/tests/AssemblyTests.cs index 66d8d41a5675b3..3c3a63c60d71f9 100644 --- a/src/libraries/System.Reflection/tests/AssemblyTests.cs +++ b/src/libraries/System.Reflection/tests/AssemblyTests.cs @@ -728,6 +728,7 @@ public void AssemblyLoadFromBytesWithSymbols() Assert.Equal(assembly.FullName, loadedAssembly.FullName); } +#pragma warning disable CS0618 // ReflectionOnly loading is not supported on this platform. [Fact] public void AssemblyReflectionOnlyLoadFromString() { @@ -750,6 +751,7 @@ public void AssemblyReflectionOnlyLoadFromNeg() Assert.Throws(() => Assembly.ReflectionOnlyLoad(string.Empty)); Assert.Throws(() => Assembly.ReflectionOnlyLoad((byte[])null)); } +#pragma warning restore CS0618 public static IEnumerable GetModules_TestData() { From 32a86674e4942aeb76cba4d6a689aa207ae237fe Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Fri, 9 Apr 2021 00:09:13 -0700 Subject: [PATCH 3/9] Disable more warnings in test --- .../tests/System/Reflection/StrongNameKeyPairTests.cs | 4 ++-- src/libraries/System.Runtime/tests/System/Type/TypeTests.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs index 33552915f6f034..81ab9656851204 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs @@ -50,7 +50,7 @@ public void Ctor_NullKeyPairFile_ThrowsArgumentNullException() { AssertExtensions.Throws("keyPairFile", () => new StrongNameKeyPair((FileStream)null)); } - +#pragma warning disable CS0618 // Strong-name signing is not supported on this platform. [Theory] [InlineData(null)] [InlineData("")] @@ -72,7 +72,7 @@ public void PublicKey_Get_ThrowsPlatformNotSupportedException() var keyPair = new StrongNameKeyPair(new byte[0]); Assert.Throws(() => keyPair.PublicKey); } - +#pragma warning restore CS0618 [Fact] public void GetObjectData_Invoke_ThrowsPlatformNotSupportedException() { diff --git a/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs b/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs index d801b567140a28..6c9196814ebb62 100644 --- a/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs +++ b/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs @@ -570,9 +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. 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 } [Fact] From ef2f8a62991f0ab5075d5a7db68a1aecaf5b9541 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Sun, 18 Apr 2021 11:30:14 -0700 Subject: [PATCH 4/9] Clean up all StrongNameKeyPair references --- .../System/Reflection/AssemblyName.CoreCLR.cs | 4 +- .../src/System/Reflection/RuntimeAssembly.cs | 3 +- src/coreclr/vm/assemblyspec.cpp | 1 - src/coreclr/vm/corelib.h | 4 +- src/coreclr/vm/metasig.h | 4 +- src/coreclr/vm/object.h | 2 - .../Common/src/System/Obsoletions.cs | 3 + src/libraries/Directory.Build.targets | 2 +- .../src/System/Reflection/AssemblyName.cs | 7 +-- .../System/Reflection/StrongNameKeyPair.cs | 25 ++------ .../System.Runtime/ref/System.Runtime.cs | 4 +- .../Reflection/StrongNameKeyPairTests.cs | 60 +++++-------------- 12 files changed, 35 insertions(+), 84 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs index b7336964c2ceb4..bc7421a1d1ea27 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs @@ -31,8 +31,7 @@ internal AssemblyName(string? name, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, string? codeBase, - AssemblyNameFlags flags, - StrongNameKeyPair? keyPair) // Null if ref, matching Assembly if def + AssemblyNameFlags flags) { _name = name; _publicKey = publicKey; @@ -43,7 +42,6 @@ internal AssemblyName(string? name, _versionCompatibility = versionCompatibility; _codeBase = codeBase; _flags = flags; - _strongNameKeyPair = keyPair; } [MethodImpl(MethodImplOptions.InternalCall)] diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 2f780028221664..89fb20181a83e4 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -114,8 +114,7 @@ public override AssemblyName GetName(bool copiedName) GetHashAlgorithm(), AssemblyVersionCompatibility.SameMachine, codeBase, - GetFlags() | AssemblyNameFlags.PublicKey, - null); // strong name key pair + GetFlags() | AssemblyNameFlags.PublicKey); Module manifestModule = ManifestModule; if (manifestModule.MDStreamVersion > 0x10000) diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 946f5856f7ca21..19b90e2ffce391 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -553,7 +553,6 @@ void AssemblySpec::AssemblyNameInit(ASSEMBLYNAMEREF* pAsmName, PEImage* pImageIn (ARG_SLOT) 1, // AssemblyVersionCompatibility.SameMachine ObjToArgSlot(gc.CodeBase), (ARG_SLOT) m_dwFlags, - (ARG_SLOT) NULL // key pair }; init.Call(MethodArgs); diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index 3b870b718d1352..7ea15ca8d213fd 100644 --- a/src/coreclr/vm/corelib.h +++ b/src/coreclr/vm/corelib.h @@ -120,7 +120,7 @@ DEFINE_FIELD_U(_hashAlgorithm, AssemblyNameBaseObject, _hashAlgorith DEFINE_FIELD_U(_versionCompatibility, AssemblyNameBaseObject, _versionCompatibility) DEFINE_FIELD_U(_flags, AssemblyNameBaseObject, _flags) DEFINE_CLASS(ASSEMBLY_NAME, Reflection, AssemblyName) -DEFINE_METHOD(ASSEMBLY_NAME, CTOR, .ctor, IM_Str_ArrB_ArrB_Ver_CI_AHA_AVC_Str_ANF_SNKP_RetV) +DEFINE_METHOD(ASSEMBLY_NAME, CTOR, .ctor, IM_Str_ArrB_ArrB_Ver_CI_AHA_AVC_Str_ANF_RetV) DEFINE_METHOD(ASSEMBLY_NAME, SET_PROC_ARCH_INDEX, SetProcArchIndex, IM_PEK_IFM_RetV) DEFINE_CLASS_U(System, Version, VersionBaseObject) @@ -858,8 +858,6 @@ DEFINE_METHOD(STRING_BUILDER, INTERNAL_COPY, InternalCopy, DEFINE_METHOD(STRING_BUILDER, REPLACE_BUFFER_INTERNAL,ReplaceBufferInternal, IM_PtrChar_Int_RetVoid) DEFINE_METHOD(STRING_BUILDER, REPLACE_BUFFER_ANSI_INTERNAL,ReplaceBufferAnsiInternal, IM_PtrSByt_Int_RetVoid) -DEFINE_CLASS(STRONG_NAME_KEY_PAIR, Reflection, StrongNameKeyPair) - DEFINE_CLASS_U(Threading, SynchronizationContext, SynchronizationContextObject) DEFINE_FIELD_U(_requireWaitNotification, SynchronizationContextObject, _requireWaitNotification) DEFINE_CLASS(SYNCHRONIZATION_CONTEXT, Threading, SynchronizationContext) diff --git a/src/coreclr/vm/metasig.h b/src/coreclr/vm/metasig.h index 84948f65242cdb..a44f64dd1c912f 100644 --- a/src/coreclr/vm/metasig.h +++ b/src/coreclr/vm/metasig.h @@ -369,8 +369,8 @@ DEFINE_METASIG(IM(RetInt, _, i)) DEFINE_METASIG_T(IM(RetAssemblyName, _, C(ASSEMBLY_NAME))) DEFINE_METASIG_T(IM(RetAssemblyBase, _, C(ASSEMBLYBASE))) DEFINE_METASIG_T(IM(RetModule, _, C(MODULE))) -DEFINE_METASIG_T(IM(Str_ArrB_ArrB_Ver_CI_AHA_AVC_Str_ANF_SNKP_RetV, - s a(b) a(b) C(VERSION) C(CULTURE_INFO) g(ASSEMBLY_HASH_ALGORITHM) g(ASSEMBLY_VERSION_COMPATIBILITY) s g(ASSEMBLY_NAME_FLAGS) C(STRONG_NAME_KEY_PAIR), v)) +DEFINE_METASIG_T(IM(Str_ArrB_ArrB_Ver_CI_AHA_AVC_Str_ANF_RetV, + s a(b) a(b) C(VERSION) C(CULTURE_INFO) g(ASSEMBLY_HASH_ALGORITHM) g(ASSEMBLY_VERSION_COMPATIBILITY) s g(ASSEMBLY_NAME_FLAGS), v)) DEFINE_METASIG_T(IM(PEK_IFM_RetV, g(PORTABLE_EXECUTABLE_KINDS) g(IMAGE_FILE_MACHINE), v)) DEFINE_METASIG(IM(RetObj, _, j)) diff --git a/src/coreclr/vm/object.h b/src/coreclr/vm/object.h index c53ce1e88a1af3..82fb0e6da2ea79 100644 --- a/src/coreclr/vm/object.h +++ b/src/coreclr/vm/object.h @@ -1502,7 +1502,6 @@ class AssemblyNameBaseObject : public Object OBJECTREF _cultureInfo; OBJECTREF _codeBase; OBJECTREF _version; - OBJECTREF _strongNameKeyPair; DWORD _hashAlgorithm; DWORD _versionCompatibility; DWORD _flags; @@ -1515,7 +1514,6 @@ class AssemblyNameBaseObject : public Object OBJECTREF GetSimpleName() { LIMITED_METHOD_CONTRACT; return _name; } U1ARRAYREF GetPublicKey() { LIMITED_METHOD_CONTRACT; return _publicKey; } U1ARRAYREF GetPublicKeyToken() { LIMITED_METHOD_CONTRACT; return _publicKeyToken; } - OBJECTREF GetStrongNameKeyPair() { LIMITED_METHOD_CONTRACT; return _strongNameKeyPair; } OBJECTREF GetCultureInfo() { LIMITED_METHOD_CONTRACT; return _cultureInfo; } OBJECTREF GetAssemblyCodeBase() { LIMITED_METHOD_CONTRACT; return _codeBase; } OBJECTREF GetVersion() { LIMITED_METHOD_CONTRACT; return _version; } diff --git a/src/libraries/Common/src/System/Obsoletions.cs b/src/libraries/Common/src/System/Obsoletions.cs index a4f6fb66e1f756..200c63b0bc5d0c 100644 --- a/src/libraries/Common/src/System/Obsoletions.cs +++ b/src/libraries/Common/src/System/Obsoletions.cs @@ -51,5 +51,8 @@ internal static class Obsoletions internal const string DisablePrivateReflectionAttributeMessage = "DisablePrivateReflectionAttribute has no effect in .NET 6.0+ applications."; internal const string DisablePrivateReflectionAttributeDiagId = "SYSLIB0015"; + + internal const string StrongNameKeyPairMessage = "Strong name signing is not supported on this platform."; + internal const string StrongNameKeyPairDiagId = "SYSLIB0017"; } } diff --git a/src/libraries/Directory.Build.targets b/src/libraries/Directory.Build.targets index 96fc0a734f8fa3..69d77e2425567d 100644 --- a/src/libraries/Directory.Build.targets +++ b/src/libraries/Directory.Build.targets @@ -17,7 +17,7 @@ $(NoWarn);nullable;CA1052 - $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015 + $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0016 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 a1760e2734d1a3..27ccbd4980d2c8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs @@ -19,8 +19,6 @@ public sealed partial class AssemblyName : ICloneable, IDeserializationCallback, private string? _codeBase; private Version? _version; - private StrongNameKeyPair? _strongNameKeyPair; - private AssemblyHashAlgorithm _hashAlgorithm; private AssemblyVersionCompatibility _versionCompatibility; @@ -200,10 +198,11 @@ public AssemblyVersionCompatibility VersionCompatibility set => _versionCompatibility = value; } + [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId)] public StrongNameKeyPair? KeyPair { - get => _strongNameKeyPair; - set => _strongNameKeyPair = value; + get => throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); + set => throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); } public string FullName 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 3f3cb11ee72cdf..1a3be7eb595316 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs @@ -6,34 +6,21 @@ namespace System.Reflection { + [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId)] public class StrongNameKeyPair : IDeserializationCallback, ISerializable { - // Build key pair from file. - public StrongNameKeyPair(FileStream keyPairFile) - { - if (keyPairFile == null) - throw new ArgumentNullException(nameof(keyPairFile)); - - int length = (int)keyPairFile.Length; - byte[] keyPairArray = new byte[length]; - keyPairFile.Read(keyPairArray, 0, length); - } - - // Build key pair from byte array in memory. - public StrongNameKeyPair(byte[] keyPairArray) - { - if (keyPairArray == null) - throw new ArgumentNullException(nameof(keyPairArray)); - } + public StrongNameKeyPair(FileStream keyPairFile) => + throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); + + public StrongNameKeyPair(byte[] keyPairArray) => + throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); protected StrongNameKeyPair(SerializationInfo info, StreamingContext context) => throw new PlatformNotSupportedException(); - [Obsolete("Strong-name signing is not supported on this platform.")] public StrongNameKeyPair(string keyPairContainer) => throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); - [Obsolete("Strong-name signing is not supported on this platform.")] public byte[] PublicKey => throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning); diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 385fb816af4055..e49a46427d9377 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -7925,6 +7925,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 = "SYSLIB0016")] 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 { } } @@ -8772,14 +8773,13 @@ 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 = "SYSLIB0016")] public partial class StrongNameKeyPair : System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable { public StrongNameKeyPair(byte[] keyPairArray) { } public StrongNameKeyPair(System.IO.FileStream keyPairFile) { } protected StrongNameKeyPair(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - [System.ObsoleteAttribute("Strong-name signing is not supported on this platform.")] public StrongNameKeyPair(string keyPairContainer) { } - [System.ObsoleteAttribute("Strong-name signing is not supported on this platform.")] public byte[] PublicKey { get { throw null; } } void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { } void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } diff --git a/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs index 81ab9656851204..86ad7ac90256bf 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs @@ -4,53 +4,43 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Serialization; +using System.Tests; using Xunit; namespace System.Reflection.Tests { public class StrongNameKeyPairTests : FileCleanupTestBase { - public static IEnumerable Ctor_ByteArray_TestData() - { - yield return new object[] { new byte[] { 7, 2, 0, 0, 0, 36, 0, 0, 82, 83, 65, 50, 0, 4, 0, 0, 1, 0, 1, 0, 171, 157, 248, 5, 104, 59, 240, 8, 24, 167, 113, 157, 119, 211, 91, 102, 217, 109, 111, 113, 99, 55, 124, 119, 90, 1, 114, 103, 221, 223, 66, 248, 122, 130, 237, 95, 97, 174, 90, 116, 24, 53, 75, 217, 196, 170, 198, 196, 147, 194, 154, 172, 143, 83, 255, 238, 84, 162, 155, 253, 219, 180, 172, 10, 206, 240, 74, 167, 54, 131, 226, 11, 23, 254, 104, 61, 231, 57, 156, 80, 118, 153, 104, 208, 106, 181, 242, 84, 178, 128, 13, 223, 98, 252, 228, 26, 176, 61, 114, 79, 166, 165, 172, 203, 91, 220, 33, 131, 250, 178, 137, 212, 59, 109, 223, 195, 132, 24, 67, 253, 88, 186, 113, 102, 229, 237, 208, 168, 5, 232, 20, 9, 220, 14, 22, 65, 4, 89, 164, 97, 7, 242, 146, 235, 181, 141, 106, 16, 183, 91, 95, 208, 86, 186, 53, 169, 111, 179, 42, 98, 42, 110, 132, 235, 154, 164, 85, 179, 87, 51, 15, 43, 202, 189, 148, 224, 204, 229, 61, 23, 52, 199, 131, 72, 27, 97, 28, 207, 249, 135, 44, 219, 239, 205, 136, 79, 205, 158, 195, 251, 127, 181, 83, 202, 165, 68, 33, 36, 226, 227, 27, 199, 84, 150, 200, 15, 104, 222, 174, 182, 159, 17, 249, 23, 27, 93, 50, 242, 63, 244, 132, 102, 183, 186, 214, 166, 121, 62, 197, 54, 118, 230, 181, 10, 21, 66, 174, 110, 113, 62, 100, 190, 58, 83, 46, 197, 41, 7, 161, 146, 178, 153, 173, 10, 187, 86, 171, 10, 62, 98, 100, 252, 18, 36, 160, 122, 241, 10, 3, 199, 83, 89, 163, 213, 100, 48, 198, 203, 36, 108, 175, 47, 111, 18, 171, 169, 238, 152, 247, 153, 88, 105, 35, 156, 83, 249, 43, 16, 23, 148, 245, 237, 26, 214, 250, 137, 10, 47, 124, 162, 21, 66, 110, 45, 200, 18, 60, 195, 221, 155, 179, 39, 160, 196, 172, 253, 81, 247, 186, 115, 129, 146, 148, 245, 238, 101, 91, 196, 133, 252, 246, 119, 170, 155, 191, 36, 144, 62, 9, 65, 119, 212, 194, 212, 159, 169, 192, 136, 17, 91, 63, 238, 203, 140, 104, 167, 156, 39, 186, 189, 125, 202, 102, 88, 64, 171, 173, 38, 41, 125, 164, 91, 174, 4, 104, 148, 6, 205, 237, 115, 115, 254, 85, 62, 203, 233, 213, 83, 44, 132, 156, 239, 205, 149, 138, 250, 11, 183, 173, 190, 225, 204, 145, 98, 194, 121, 232, 155, 194, 170, 219, 147, 216, 173, 250, 236, 44, 122, 126, 252, 126, 75, 115, 254, 103, 106, 51, 102, 141, 150, 115, 47, 177, 46, 189, 114, 242, 250, 114, 82, 23, 102, 113, 119, 197, 115, 67, 111, 59, 71, 39, 160, 166, 135, 136, 17, 247, 3, 227, 205, 27, 42, 86, 173, 40, 65, 3, 127, 63, 112, 204, 19, 247, 243, 74, 104, 120, 194, 51, 238, 235, 6, 46, 62, 129, 214, 201, 170, 65, 254, 78, 201, 76, 78, 219, 235, 170, 196, 112, 87, 64, 130, 178, 109, 114, 221, 222, 92, 138, 201, 236, 20, 167, 240, 23, 108, 106, 63, 171, 74, 227, 158, 62, 3, 224, 197, 110, 218, 215, 210, 63, 90, 154, 29, 188, 183, 89, 18, 143, 170, 69, 53, 80, 44, 214, 169, 9, 68, 174, 238, 102, 199, 178, 251, 17, 15 } }; - yield return new object[] { new byte[0] }; - } - - [Theory] - [MemberData(nameof(Ctor_ByteArray_TestData))] - public void Ctor_ByteArray(byte[] keyPairArray) +#pragma warning disable SYSLIB0016 // Strong name signing is not supported on this platform. + [Fact] + public void Ctor_ByteArray_ThrowsPlatformNotSupportedException() { - // Can't validate anything as this is a nop in .NET Core. - // Just make sure it doesn't throw. - var keyPair = new StrongNameKeyPair(keyPairArray); + AssertExtensions.Throws(() => new StrongNameKeyPair(new byte[] { 7, 2, 0, 0 })); } [Fact] - public void Ctor_NullKeyPairArray_ThrowsArgumentNullException() + public void Ctor_NullKeyPairArray_ThrowsPlatformNotSupportedException() { - AssertExtensions.Throws("keyPairArray", () => new StrongNameKeyPair((byte[])null)); + AssertExtensions.Throws(() => new StrongNameKeyPair((byte[])null)); } - [Theory] - [MemberData(nameof(Ctor_ByteArray_TestData))] - public void Ctor_FileStream(byte[] keyPairArray) + [Fact] + public void Ctor_FileStream_ThrowsPlatformNotSupportedException() { string tempPath = GetTestFilePath(); - File.WriteAllBytes(tempPath, keyPairArray); + File.WriteAllBytes(tempPath, new byte[] { 7, 2, 0, 0 }); using (FileStream fileStream = File.OpenRead(tempPath)) { - // Can't validate anything as this is a nop in .NET Core. - // Just make sure it doesn't throw. - var keyPair = new StrongNameKeyPair(fileStream); + AssertExtensions.Throws(() => new StrongNameKeyPair(fileStream)); } } [Fact] - public void Ctor_NullKeyPairFile_ThrowsArgumentNullException() + public void Ctor_NullKeyPairFile_ThrowsPlatformNotSupportedException() { - AssertExtensions.Throws("keyPairFile", () => new StrongNameKeyPair((FileStream)null)); + AssertExtensions.Throws(() => new StrongNameKeyPair((FileStream)null)); } -#pragma warning disable CS0618 // Strong-name signing is not supported on this platform. + [Theory] [InlineData(null)] [InlineData("")] @@ -66,32 +56,12 @@ public void Ctor_SerializationInfo_StreamingContext_ThrowsPlatformNotSupportedEx Assert.Throws(() => new SubStrongNameKeyPair(null, new StreamingContext())); } - [Fact] - public void PublicKey_Get_ThrowsPlatformNotSupportedException() - { - var keyPair = new StrongNameKeyPair(new byte[0]); - Assert.Throws(() => keyPair.PublicKey); - } -#pragma warning restore CS0618 - [Fact] - public void GetObjectData_Invoke_ThrowsPlatformNotSupportedException() - { - ISerializable keyPair = new StrongNameKeyPair(new byte[0]); - Assert.Throws(() => keyPair.GetObjectData(null, new StreamingContext())); - } - - [Fact] - public void OnDeserialization_Invoke_ThrowsPlatformNotSupportedException() - { - IDeserializationCallback keyPair = new StrongNameKeyPair(new byte[0]); - Assert.Throws(() => keyPair.OnDeserialization(null)); - } - private class SubStrongNameKeyPair : StrongNameKeyPair { public SubStrongNameKeyPair(SerializationInfo info, StreamingContext context) : base(info, context) { } } +#pragma warning restore SYSLIB0016 } } From 1e7c6096bcb7c47469c6912ef4a743542ef3a32f Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Sun, 18 Apr 2021 14:04:39 -0700 Subject: [PATCH 5/9] Update obsoletion warning ID --- src/libraries/Directory.Build.targets | 2 +- src/libraries/System.Runtime/ref/System.Runtime.cs | 4 ++-- .../tests/System/Reflection/StrongNameKeyPairTests.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libraries/Directory.Build.targets b/src/libraries/Directory.Build.targets index 8930127ab1d1bf..595051796e5af6 100644 --- a/src/libraries/Directory.Build.targets +++ b/src/libraries/Directory.Build.targets @@ -17,7 +17,7 @@ $(NoWarn);nullable;CA1052 - $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0016 + $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0017 diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 01f31c3f55229c..6655ea065f32e2 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -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 = "SYSLIB0016")] + [System.ObsoleteAttribute("Strong name signing is not supported on this platform.", DiagnosticId = "SYSLIB0017")] 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 = "SYSLIB0016")] + [System.ObsoleteAttribute("Strong name signing is not supported on this platform.", DiagnosticId = "SYSLIB0017")] 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 86ad7ac90256bf..022d52b63d7180 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 SYSLIB0016 // Strong name signing is not supported on this platform. +#pragma warning disable SYSLIB0017 // Strong name signing is not supported on this platform. [Fact] public void Ctor_ByteArray_ThrowsPlatformNotSupportedException() { @@ -62,6 +62,6 @@ public SubStrongNameKeyPair(SerializationInfo info, StreamingContext context) : { } } -#pragma warning restore SYSLIB0016 +#pragma warning restore SYSLIB0017 } } From edd505905d084f6261f04e4f97e858c3f9d7e608 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Sun, 18 Apr 2021 15:10:53 -0700 Subject: [PATCH 6/9] Add the the obsoletion into the list-of-diagnostics.md --- docs/project/list-of-diagnostics.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index 0c4093652fd08f..cefb4c20fadc33 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -28,6 +28,7 @@ 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.| ### Analyzer warnings (`SYSLIB1001` - `SYSLIB1999`) | Diagnostic ID | Description | From e20427eb4349c244a10eef0db9168fba4e693886 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 22 Apr 2021 14:22:55 -0700 Subject: [PATCH 7/9] Apply feedbacks --- docs/project/list-of-diagnostics.md | 3 ++- src/libraries/Common/src/System/Obsoletions.cs | 5 ++++- .../src/System/Reflection/Assembly.cs | 6 +++--- .../src/System/Reflection/AssemblyName.cs | 2 +- .../src/System/Reflection/StrongNameKeyPair.cs | 2 +- .../System.Private.CoreLib/src/System/Type.cs | 2 +- .../System.Reflection/tests/AssemblyTests.cs | 4 ++-- src/libraries/System.Runtime/ref/System.Runtime.cs | 12 ++++++------ .../System/Reflection/StrongNameKeyPairTests.cs | 2 +- .../System.Runtime/tests/System/Type/TypeTests.cs | 4 ++-- 10 files changed, 23 insertions(+), 19 deletions(-) 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] From b605f37ce45261e57f45dec699d192027f3c6154 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 22 Apr 2021 15:18:13 -0700 Subject: [PATCH 8/9] Suppress warning in mono --- src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index dc1eaef95e6f97..b8cc2847035e62 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -308,7 +308,9 @@ internal static bool IsTypeDefinition(RuntimeType type) Assembly a; try { +#pragma warning disable SYSLIB0018 // ReflectionOnly loading is not supported and throws PlatformNotSupportedException. a = Assembly.ReflectionOnlyLoad(an); +#pragma warning restore SYSLIB0018 } catch { From a548287b68297e3f57a7dd36bf4ad044b341db8c Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Fri, 23 Apr 2021 17:23:58 -0700 Subject: [PATCH 9/9] Update comment --- src/libraries/Directory.Build.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Directory.Build.targets b/src/libraries/Directory.Build.targets index ed278a660bf932..4c660f5d459fff 100644 --- a/src/libraries/Directory.Build.targets +++ b/src/libraries/Directory.Build.targets @@ -16,7 +16,7 @@ $(NoWarn);nullable $(NoWarn);nullable;CA1052 + SYSLIB0003: Code Access Security (CAS). SYSLIB0004: Constrained Execution Region (CER). SYSLIB0017: Strong name signing. --> $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0017