diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index e1d8a89857457..47ec247968859 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -66,6 +66,8 @@ The PR that reveals the implementation of the ` 0x10000) diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 580739627957b..be3b4279d7cbc 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 71ecf177e5acc..c9bc96ccb4e7c 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) @@ -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) diff --git a/src/coreclr/vm/metasig.h b/src/coreclr/vm/metasig.h index a8f5b28aca14d..83af0763e2e5d 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 5cad6621e4f4c..e35bd90fd68ab 100644 --- a/src/coreclr/vm/object.h +++ b/src/coreclr/vm/object.h @@ -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; } diff --git a/src/libraries/Common/src/System/Obsoletions.cs b/src/libraries/Common/src/System/Obsoletions.cs index d9c7d8409ea6c..7d5346ef79b6b 100644 --- a/src/libraries/Common/src/System/Obsoletions.cs +++ b/src/libraries/Common/src/System/Obsoletions.cs @@ -60,6 +60,12 @@ 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 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"; diff --git a/src/libraries/Directory.Build.targets b/src/libraries/Directory.Build.targets index 12a9854e456b8..4c660f5d459ff 100644 --- a/src/libraries/Directory.Build.targets +++ b/src/libraries/Directory.Build.targets @@ -16,8 +16,8 @@ $(NoWarn);nullable $(NoWarn);nullable;CA1052 - $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015 + SYSLIB0003: Code Access Security (CAS). SYSLIB0004: Constrained Execution Region (CER). SYSLIB0017: Strong name signing. --> + $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0017 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 9f627596efed9..ccc60df7818bc 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(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); } 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 a1760e2734d1a..13cd39a6203d3 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, 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 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 ee5ffafa706c4..7ceaaebab1fb0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs @@ -6,25 +6,14 @@ 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(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index 6b01229d10274..b04a56281833d 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(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 7424e2cd07f2b..fc2df64f79461 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 SYSLIB0018 // ReflectionOnly loading is not supported and throws PlatformNotSupportedException. [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 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 43e498719e324..ff4f47dc9256a 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -4571,6 +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 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 @@ 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 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 @@ 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 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 @@ 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 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 33552915f6f03..10cf716f58330 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/StrongNameKeyPairTests.cs @@ -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 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(() => 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)); } [Theory] @@ -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); - } - - [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 SYSLIB0017 } } diff --git a/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs b/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs index d801b567140a2..a7e21552fcd61 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 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 SYSLIB0018 } [Fact] diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index dc1eaef95e6f9..b8cc2847035e6 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 {