From 52cf2651e88920009ab57227736ff633cd3f800d Mon Sep 17 00:00:00 2001 From: Bar Arnon Date: Thu, 23 Sep 2021 15:18:58 +0300 Subject: [PATCH 1/7] Obsolete thumbtacked AssemblyName properties Fix #59061 --- docs/project/list-of-diagnostics.md | 3 +++ src/libraries/Common/src/System/Obsoletions.cs | 9 +++++++++ .../src/System/Reflection/AssemblyName.cs | 3 +++ 3 files changed, 15 insertions(+) diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index 6aefa3a3890d3c..be5d0fc3aa1962 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -90,6 +90,9 @@ The PR that reveals the implementation of the ` _hashAlgorithm; set => _hashAlgorithm = value; } + [Obsolete(Obsoletions.AssemblyVersionCompatibilityMessage, DiagnosticId = Obsoletions.AssemblyVersionCompatibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public AssemblyVersionCompatibility VersionCompatibility { get => _versionCompatibility; From ec9f7aefa9fe0e7e4b30562c6e40d5eb8bd59480 Mon Sep 17 00:00:00 2001 From: Bar Arnon Date: Thu, 23 Sep 2021 15:40:46 +0300 Subject: [PATCH 2/7] Ignore obsoletion --- .../src/System/Reflection/AssemblyName.CoreCLR.cs | 2 ++ 1 file changed, 2 insertions(+) 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 bc7421a1d1ea27..404fa6227071ec 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 @@ -63,7 +63,9 @@ internal static AssemblyName GetFileInformationCore(string assemblyFile) internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm) { +#pragma warning disable 618 ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _flags); +#pragma warning restore 618 } internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) From 486b8753f69bd3d5902830a879e218fd43eb81a6 Mon Sep 17 00:00:00 2001 From: Bar Arnon Date: Thu, 23 Sep 2021 16:05:51 +0300 Subject: [PATCH 3/7] Fix pragma --- .../src/System/Reflection/AssemblyName.CoreCLR.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 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 404fa6227071ec..664168b5aefe8f 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 @@ -63,9 +63,9 @@ internal static AssemblyName GetFileInformationCore(string assemblyFile) internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm) { -#pragma warning disable 618 +#pragma warning disable SYSLIB0037 ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _flags); -#pragma warning restore 618 +#pragma warning restore SYSLIB0037 } internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) From 9f05e44d293040a550a2780e9b39d3f3ab865594 Mon Sep 17 00:00:00 2001 From: Jeff Handley Date: Mon, 15 Nov 2021 17:45:47 +0000 Subject: [PATCH 4/7] Merge the AssemblyName member obsoletions into a single diagnostic id --- docs/project/list-of-diagnostics.md | 4 +--- .../src/System/Reflection/AssemblyName.CoreCLR.cs | 4 ++-- src/libraries/Common/src/System/Obsoletions.cs | 10 ++-------- .../src/System/Reflection/AssemblyName.cs | 6 +++--- src/libraries/System.Runtime/ref/System.Runtime.cs | 3 +++ 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index be5d0fc3aa1962..2924b73749635f 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -90,9 +90,7 @@ The PR that reveals the implementation of the ` _hashAlgorithm; set => _hashAlgorithm = value; } - [Obsolete(Obsoletions.AssemblyVersionCompatibilityMessage, DiagnosticId = Obsoletions.AssemblyVersionCompatibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [Obsolete(Obsoletions.AssemblyNameMembersMessage, DiagnosticId = Obsoletions.AssemblyNameMembersDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public AssemblyVersionCompatibility VersionCompatibility { get => _versionCompatibility; diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index a7042b6bb17357..84206349dd7dd2 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -11361,12 +11361,15 @@ public AssemblyName(string assemblyName) { } public string? EscapedCodeBase { get { throw null; } } public System.Reflection.AssemblyNameFlags Flags { get { throw null; } set { } } public string FullName { get { throw null; } } + [System.ObsoleteAttribute("AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported.", DiagnosticId = "SYSLIB0036", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] 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 { } } + [System.ObsoleteAttribute("AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported.", DiagnosticId = "SYSLIB0036", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public System.Reflection.ProcessorArchitecture ProcessorArchitecture { get { throw null; } set { } } public System.Version? Version { get { throw null; } set { } } + [System.ObsoleteAttribute("AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported.", DiagnosticId = "SYSLIB0036", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public System.Configuration.Assemblies.AssemblyVersionCompatibility VersionCompatibility { get { throw null; } set { } } public object Clone() { throw null; } public static System.Reflection.AssemblyName GetAssemblyName(string assemblyFile) { throw null; } From 8455593d3eb6268b775103b7386c04ac736c3f75 Mon Sep 17 00:00:00 2001 From: Jeff Handley Date: Mon, 15 Nov 2021 11:34:22 -0800 Subject: [PATCH 5/7] Fix pragma to use updated diagnostic id --- .../src/System/Reflection/AssemblyName.CoreCLR.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 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 6ca99ef7c431a7..f45b3837abdd93 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 @@ -63,9 +63,9 @@ internal static AssemblyName GetFileInformationCore(string assemblyFile) internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm) { -#pragma warning disable SYSLIB0036 // AssemblyName.ProcessorArchitecture is obsolete +#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _flags); -#pragma warning restore SYSLIB0036 +#pragma warning restore SYSLIB0037 } internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) From b0ee59a99a2187d8d6641a7125183e026482f658 Mon Sep 17 00:00:00 2001 From: Jeff Handley Date: Mon, 15 Nov 2021 12:47:57 -0800 Subject: [PATCH 6/7] Suppress SYSLIB0037 in reflection tests --- .../tests/System.Reflection.Metadata.Tests.csproj | 4 +++- .../tests/System.Reflection.MetadataLoadContext.Tests.csproj | 5 +++-- .../System.Reflection/tests/System.Reflection.Tests.csproj | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj b/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj index df738508c902d8..632eea19a6e213 100644 --- a/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj +++ b/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj @@ -2,7 +2,9 @@ true false - 436 + + $(NoWarn);436;SYSLIB0037 $(NetCoreAppCurrent);$(NetFrameworkMinimum) true diff --git a/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj b/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj index 78f831c71d4988..32e2dcef87db85 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj +++ b/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj @@ -2,8 +2,9 @@ true $(NetCoreAppCurrent);$(NetFrameworkMinimum) - - $(NoWarn);SYSLIB0005 + + $(NoWarn);SYSLIB0005;SYSLIB0037 false true - $(NoWarn),SYSLIB0013 + + $(NoWarn);SYSLIB0013;SYSLIB0037 true From 8d62a802eb91bdcfe212f7d86552cf0750d1d354 Mon Sep 17 00:00:00 2001 From: Jeff Handley Date: Mon, 15 Nov 2021 22:28:08 +0000 Subject: [PATCH 7/7] Suppress SYSLIB0037 warnings --- .../System/Reflection/Metadata/MetadataReader.netstandard.cs | 2 ++ .../System/Reflection/TypeLoading/General/AssemblyNameData.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.netstandard.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.netstandard.cs index d85eb360d07d02..a4e71b93171a62 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.netstandard.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.netstandard.cs @@ -16,7 +16,9 @@ internal AssemblyName GetAssemblyName(StringHandle nameHandle, Version version, { Version = version, CultureName = cultureName, +#pragma warning disable SYSLIB0037 // AssemblyName.HashAlgorithm is obsolete HashAlgorithm = hashAlgorithm, +#pragma warning restore Flags = GetAssemblyNameFlags(flags), ContentType = GetContentTypeFromAssemblyFlags(flags) }; diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/AssemblyNameData.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/AssemblyNameData.cs index 0b4be9e4c6bd49..5f605050c9b847 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/AssemblyNameData.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/AssemblyNameData.cs @@ -32,8 +32,10 @@ public AssemblyName CreateAssemblyName() Version = Version, CultureName = CultureName, ContentType = ContentType, +#pragma warning disable SYSLIB0037 // AssemblyName members HashAlgorithm and ProcessorArchitecture are obsolete HashAlgorithm = HashAlgorithm, ProcessorArchitecture = ProcessorArchitecture +#pragma warning restore }; // Yes, *we* have to clone the array. AssemblyName.SetPublicKey() violates framework guidelines and doesn't make a copy.