Annotate unsupported APIs in .Net core as Obsolete - Reflection area (#50941)
authorBuyaa Namnan <bunamnan@microsoft.com>
Sun, 25 Apr 2021 20:09:54 +0000 (13:09 -0700)
committerGitHub <noreply@github.com>
Sun, 25 Apr 2021 20:09:54 +0000 (13:09 -0700)
* Annotate unsupported APIs in .Net core as Obsolete - Reflection area

18 files changed:
docs/project/list-of-diagnostics.md
src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
src/coreclr/vm/assemblyspec.cpp
src/coreclr/vm/corelib.h
src/coreclr/vm/metasig.h
src/coreclr/vm/object.h
src/libraries/Common/src/System/Obsoletions.cs
src/libraries/Directory.Build.targets
src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs
src/libraries/System.Private.CoreLib/src/System/Type.cs
src/libraries/System.Reflection/tests/AssemblyTests.cs
src/libraries/System.Runtime/ref/System.Runtime.cs
src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs
src/libraries/System.Runtime/tests/System/Type/TypeTests.cs
src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs

index e1d8a89..47ec247 100644 (file)
@@ -66,6 +66,8 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
 |  __`SYSLIB0014`__ | WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient 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 and throws PlatformNotSupportedException. |
+|  __`SYSLIB0018`__ | ReflectionOnly loading is not supported and throws PlatformNotSupportedException. |
 |  __`SYSLIB0019`__ | RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException. |
 |  __`SYSLIB0020`__ | JsonSerializerOptions.IgnoreNullValues is obsolete. To ignore null values when serializing, set DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull. |
 
index b733696..bc7421a 100644 (file)
@@ -31,8 +31,7 @@ namespace System.Reflection
             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 @@ namespace System.Reflection
             _versionCompatibility = versionCompatibility;
             _codeBase = codeBase;
             _flags = flags;
-            _strongNameKeyPair = keyPair;
         }
 
         [MethodImpl(MethodImplOptions.InternalCall)]
index 2f78002..89fb201 100644 (file)
@@ -114,8 +114,7 @@ namespace System.Reflection
                     GetHashAlgorithm(),
                     AssemblyVersionCompatibility.SameMachine,
                     codeBase,
-                    GetFlags() | AssemblyNameFlags.PublicKey,
-                    null); // strong name key pair
+                    GetFlags() | AssemblyNameFlags.PublicKey);
 
             Module manifestModule = ManifestModule;
             if (manifestModule.MDStreamVersion > 0x10000)
index 5807396..be3b427 100644 (file)
@@ -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);
index 71ecf17..c9bc96c 100644 (file)
@@ -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)
@@ -864,8 +864,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)
index a8f5b28..83af076 100644 (file)
@@ -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))
index 5cad662..e35bd90 100644 (file)
@@ -1535,7 +1535,6 @@ class AssemblyNameBaseObject : public Object
     OBJECTREF     _cultureInfo;
     OBJECTREF     _codeBase;
     OBJECTREF     _version;
-    OBJECTREF     _strongNameKeyPair;
     DWORD         _hashAlgorithm;
     DWORD         _versionCompatibility;
     DWORD         _flags;
@@ -1548,7 +1547,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; }
index d9c7d84..7d5346e 100644 (file)
@@ -60,6 +60,12 @@ namespace System
         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 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";
+
         internal const string RuntimeEnvironmentMessage = "RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.";
         internal const string RuntimeEnvironmentDiagId = "SYSLIB0019";
 
index 12a9854..4c660f5 100644 (file)
@@ -16,8 +16,8 @@
     <NoWarn Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' or '$(TargetFrameworkIdentifier)' == '.NETStandard' or ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '3.0')))">$(NoWarn);nullable</NoWarn>
     <NoWarn Condition="'$(GeneratePlatformNotSupportedAssembly)' == 'true' or '$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">$(NoWarn);nullable;CA1052</NoWarn>
     <!-- Ignore Obsolete errors within the generated shims that type-forward types.
-         SYSLIB0003 is for CAS. SYSLIB0004 is the obsoletion of CER. -->
-    <NoWarn Condition="'$(IsPartialFacadeAssembly)' == 'true'">$(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015</NoWarn>
+         SYSLIB0003: Code Access Security (CAS). SYSLIB0004: Constrained Execution Region (CER). SYSLIB0017: Strong name signing. -->
+    <NoWarn Condition="'$(IsPartialFacadeAssembly)' == 'true'">$(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0017</NoWarn>
     <!-- Reset these properties back to blank, since they are defaulted by Microsoft.NET.Sdk -->
     <WarningsAsErrors Condition="'$(WarningsAsErrors)' == 'NU1605'" />
     <!-- Set the documentation output file globally. -->
index 9f62759..ccc60df 100644 (file)
@@ -372,10 +372,13 @@ namespace System.Reflection
         [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(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(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(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); }
 
index a1760e2..13cd39a 100644 (file)
@@ -19,8 +19,6 @@ namespace System.Reflection
         private string? _codeBase;
         private Version? _version;
 
-        private StrongNameKeyPair? _strongNameKeyPair;
-
         private AssemblyHashAlgorithm _hashAlgorithm;
 
         private AssemblyVersionCompatibility _versionCompatibility;
@@ -200,10 +198,11 @@ namespace System.Reflection
             set => _versionCompatibility = value;
         }
 
+        [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
         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
index ee5ffaf..7ceaaeb 100644 (file)
@@ -6,25 +6,14 @@ using System.Runtime.Serialization;
 
 namespace System.Reflection
 {
+    [Obsolete(Obsoletions.StrongNameKeyPairMessage, DiagnosticId = Obsoletions.StrongNameKeyPairDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
     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();
index 6b01229..b04a562 100644 (file)
@@ -541,6 +541,7 @@ namespace System
         }
         public virtual bool Equals(Type? o) => o == null ? false : object.ReferenceEquals(this.UnderlyingSystemType, o.UnderlyingSystemType);
 
+        [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
index 7424e2c..fc2df64 100644 (file)
@@ -728,6 +728,7 @@ namespace System.Reflection.Tests
             Assert.Equal(assembly.FullName, loadedAssembly.FullName);
         }
 
+#pragma warning disable SYSLIB0018 // ReflectionOnly loading is not supported and throws PlatformNotSupportedException.
         [Fact]
         public void AssemblyReflectionOnlyLoadFromString()
         {
@@ -750,6 +751,7 @@ namespace System.Reflection.Tests
             Assert.Throws<PlatformNotSupportedException>(() => Assembly.ReflectionOnlyLoad(string.Empty));
             Assert.Throws<PlatformNotSupportedException>(() => Assembly.ReflectionOnlyLoad((byte[])null));
         }
+#pragma warning restore SYSLIB0018
 
         public static IEnumerable<object[]> GetModules_TestData()
         {
index 43e4987..ff4f47d 100644 (file)
@@ -4571,6 +4571,7 @@ namespace System
         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 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,10 +7946,13 @@ namespace System.Reflection
         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 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 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 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; }
@@ -8068,6 +8072,7 @@ namespace System.Reflection
         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 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 { } }
@@ -8915,6 +8920,7 @@ namespace System.Reflection
         public static System.Collections.Generic.IEnumerable<System.Reflection.PropertyInfo> 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 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) { }
index 3355291..10cf716 100644 (file)
@@ -4,51 +4,41 @@
 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<object[]> 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 SYSLIB0017 // Strong name signing is not supported and throws PlatformNotSupportedException.
+        [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<PlatformNotSupportedException>(() => new StrongNameKeyPair(new byte[] { 7, 2, 0, 0 }));
         }
 
         [Fact]
-        public void Ctor_NullKeyPairArray_ThrowsArgumentNullException()
+        public void Ctor_NullKeyPairArray_ThrowsPlatformNotSupportedException()
         {
-            AssertExtensions.Throws<ArgumentNullException>("keyPairArray", () => new StrongNameKeyPair((byte[])null));
+            AssertExtensions.Throws<PlatformNotSupportedException>(() => 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<PlatformNotSupportedException>(() => new StrongNameKeyPair(fileStream));
             }
         }
 
         [Fact]
-        public void Ctor_NullKeyPairFile_ThrowsArgumentNullException()
+        public void Ctor_NullKeyPairFile_ThrowsPlatformNotSupportedException()
         {
-            AssertExtensions.Throws<ArgumentNullException>("keyPairFile", () => new StrongNameKeyPair((FileStream)null));
+            AssertExtensions.Throws<PlatformNotSupportedException>(() => new StrongNameKeyPair((FileStream)null));
         }
 
         [Theory]
@@ -66,32 +56,12 @@ namespace System.Reflection.Tests
             Assert.Throws<PlatformNotSupportedException>(() => new SubStrongNameKeyPair(null, new StreamingContext()));
         }
 
-        [Fact]
-        public void PublicKey_Get_ThrowsPlatformNotSupportedException()
-        {
-            var keyPair = new StrongNameKeyPair(new byte[0]);
-            Assert.Throws<PlatformNotSupportedException>(() => keyPair.PublicKey);
-        }
-
-        [Fact]
-        public void GetObjectData_Invoke_ThrowsPlatformNotSupportedException()
-        {
-            ISerializable keyPair = new StrongNameKeyPair(new byte[0]);
-            Assert.Throws<PlatformNotSupportedException>(() => keyPair.GetObjectData(null, new StreamingContext()));
-        }
-
-        [Fact]
-        public void OnDeserialization_Invoke_ThrowsPlatformNotSupportedException()
-        {
-            IDeserializationCallback keyPair = new StrongNameKeyPair(new byte[0]);
-            Assert.Throws<PlatformNotSupportedException>(() => keyPair.OnDeserialization(null));
-        }
-
         private class SubStrongNameKeyPair : StrongNameKeyPair
         {
             public SubStrongNameKeyPair(SerializationInfo info, StreamingContext context) : base(info, context)
             {
             }
         }
+#pragma warning restore SYSLIB0017
     }
 }
index d801b56..a7e2155 100644 (file)
@@ -570,9 +570,11 @@ namespace System.Tests
         [Fact]
         public void ReflectionOnlyGetType()
         {
+#pragma warning disable SYSLIB0018 // ReflectionOnly loading is not supported and throws PlatformNotSupportedException.
             Assert.Throws<PlatformNotSupportedException>(() => Type.ReflectionOnlyGetType(null, true, false));
             Assert.Throws<PlatformNotSupportedException>(() => Type.ReflectionOnlyGetType("", true, true));
             Assert.Throws<PlatformNotSupportedException>(() => Type.ReflectionOnlyGetType("System.Tests.TypeTests", false, true));
+#pragma warning restore SYSLIB0018
         }
 
         [Fact]
index dc1eaef..b8cc284 100644 (file)
@@ -308,7 +308,9 @@ namespace System
                 Assembly a;
                 try
                 {
+#pragma warning disable SYSLIB0018 // ReflectionOnly loading is not supported and throws PlatformNotSupportedException.
                     a = Assembly.ReflectionOnlyLoad(an);
+#pragma warning restore SYSLIB0018
                 }
                 catch
                 {