From f6e4705afce023ce319f372f70b58c63a18872bd Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 15 May 2024 15:59:19 -0700 Subject: [PATCH 1/6] Mark LoadFrom overload that always throws as obsolete Fixes #96410 --- .../CompatibilitySuppressions.xml | 22 +++++++++++++++++++ .../Common/src/System/Obsoletions.cs | 3 +++ .../src/System/Reflection/Assembly.cs | 1 + 3 files changed, 26 insertions(+) diff --git a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml index 97b65a2748409e..480b91f1286266 100644 --- a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -1,6 +1,22 @@  + + CP0001 + T:Internal.Console + + + CP0001 + T:System.Runtime.CompilerServices.ICastable + + + CP0002 + F:System.Resources.ResourceManager.BaseNameField + + + CP0002 + F:System.Resources.ResourceSet.Reader + CP0015 M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] @@ -29,4 +45,10 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + + CP0016 + M:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm):[T:System.ObsoleteAttribute] + ref/net9.0/System.Private.CoreLib.dll + lib/net9.0/System.Private.CoreLib.dll + \ No newline at end of file diff --git a/src/libraries/Common/src/System/Obsoletions.cs b/src/libraries/Common/src/System/Obsoletions.cs index 3e68a4e3cd2def..318a466f840613 100644 --- a/src/libraries/Common/src/System/Obsoletions.cs +++ b/src/libraries/Common/src/System/Obsoletions.cs @@ -177,5 +177,8 @@ internal static class Obsoletions internal const string ArmIntrinsicPerformsUnsignedOperationMessage = "The underlying hardware instruction does not perform a signed saturate narrowing operation, and it always returns an unsigned result. Use the unsigned overload instead."; internal const string ArmIntrinsicPerformsUnsignedOperationDiagId = "SYSLIB0055"; + + internal const string LoadFromHashAlgorithmMessage = "LoadFrom with a custom AssemblyHashAlgorithm is obsolete. Use overloads without an AssemblyHashAlgorithm."; + internal const string LoadFromHashAlgorithmDiagId = "SYSLIB0056"; } } 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 d467fd6fb08242..b8348d4bbfc227 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -385,6 +385,7 @@ public static Assembly LoadFrom(string assemblyFile) } [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")] + [Obsolete(Obsoletions.LoadFromHashAlgorithmMessage, DiagnosticId = Obsoletions.LoadFromHashAlgorithmDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm) { throw new NotSupportedException(SR.NotSupported_AssemblyLoadFromHash); From 731f83948e61c3bbc17e02ebe90f7be29c0c0031 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 15 May 2024 20:01:36 -0700 Subject: [PATCH 2/6] Correct suppressions --- .../CompatibilitySuppressions.xml | 16 ---------------- .../src/CompatibilitySuppressions.xml | 8 +++++++- .../CompatibilitySuppressions.xml | 8 +++++++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml index 480b91f1286266..000ebea99877ae 100644 --- a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -1,22 +1,6 @@  - - CP0001 - T:Internal.Console - - - CP0001 - T:System.Runtime.CompilerServices.ICastable - - - CP0002 - F:System.Resources.ResourceManager.BaseNameField - - - CP0002 - F:System.Resources.ResourceSet.Reader - CP0015 M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index 770514a671adfc..163651494d4281 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -865,4 +865,10 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - + + CP0016 + M:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm):[T:System.ObsoleteAttribute] + ref/net9.0/System.Private.CoreLib.dll + lib/net9.0/System.Private.CoreLib.dll + + \ No newline at end of file diff --git a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml index 8e96fb8cbaa781..1e3176ca3858ef 100644 --- a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -32,4 +32,10 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - + + CP0016 + M:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm):[T:System.ObsoleteAttribute] + ref/net9.0/System.Private.CoreLib.dll + lib/net9.0/System.Private.CoreLib.dll + + \ No newline at end of file From b4d4bf224b02e3c5d8fee759d0d679ce2308bdc5 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 16 May 2024 14:34:25 -0700 Subject: [PATCH 3/6] Update ref assembly and remove suppression --- .../System.Private.CoreLib/CompatibilitySuppressions.xml | 6 ------ .../src/CompatibilitySuppressions.xml | 6 ------ src/libraries/System.Runtime/ref/System.Runtime.cs | 1 + .../System.Private.CoreLib/CompatibilitySuppressions.xml | 6 ------ 4 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml index 000ebea99877ae..97b65a2748409e 100644 --- a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -29,10 +29,4 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - CP0016 - M:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm):[T:System.ObsoleteAttribute] - ref/net9.0/System.Private.CoreLib.dll - lib/net9.0/System.Private.CoreLib.dll - \ No newline at end of file diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index 163651494d4281..a9e29a605e36bb 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -865,10 +865,4 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - CP0016 - M:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm):[T:System.ObsoleteAttribute] - ref/net9.0/System.Private.CoreLib.dll - lib/net9.0/System.Private.CoreLib.dll - \ No newline at end of file diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 0c2d57c8f5eafd..a339692fd2fdf2 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -11139,6 +11139,7 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")] public static System.Reflection.Assembly LoadFrom(string assemblyFile) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")] + [System.ObsoleteAttribute("LoadFrom with a custom AssemblyHashAlgorithm is obsolete. Use overloads without an AssemblyHashAlgorithm.", DiagnosticId = "SYSLIB0056", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Reflection.Assembly LoadFrom(string assemblyFile, byte[]? hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded module depends on might be removed")] public System.Reflection.Module LoadModule(string moduleName, byte[]? rawModule) { throw null; } diff --git a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml index 1e3176ca3858ef..bce808f1690e4b 100644 --- a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -32,10 +32,4 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - CP0016 - M:System.Reflection.Assembly.LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm):[T:System.ObsoleteAttribute] - ref/net9.0/System.Private.CoreLib.dll - lib/net9.0/System.Private.CoreLib.dll - \ No newline at end of file From bc79688c6967daaed07334270336a9c141cf4b66 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 17 May 2024 09:05:10 -0700 Subject: [PATCH 4/6] Suppress obsolete warnings in unit tests --- .../tests/System.Reflection.Tests/AssemblyTests.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Reflection.Tests/AssemblyTests.cs b/src/libraries/System.Runtime/tests/System.Reflection.Tests/AssemblyTests.cs index 600a4733b40c9c..07bf148c256bfe 100644 --- a/src/libraries/System.Runtime/tests/System.Reflection.Tests/AssemblyTests.cs +++ b/src/libraries/System.Runtime/tests/System.Reflection.Tests/AssemblyTests.cs @@ -442,12 +442,20 @@ public void LoadFile_ValidPEBadIL_ThrowsBadImageFormatExceptionWithPath_ByInitia AssertExtensions.ThrowsContains(() => Assembly.LoadFile(path), path); } +#pragma warning disable SYSLIB0056 // AssemblyHashAlgorithm overload is not supported and throws NotSupportedException. [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))] public void LoadFromUsingHashValue() { Assert.Throws(() => Assembly.LoadFrom("abc", null, System.Configuration.Assemblies.AssemblyHashAlgorithm.SHA1)); } + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))] + public void LoadFrom_WithHashValue_ThrowsNotSupportedException() + { + Assert.Throws(() => Assembly.LoadFrom(DestTestAssemblyPath, new byte[0], Configuration.Assemblies.AssemblyHashAlgorithm.None)); + } +#pragma warning restore SYSLIB0056 // AssemblyHashAlgorithm overload is not supported and throws NotSupportedException. + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))] public void LoadFrom_SamePath_ReturnsEqualAssemblies() { @@ -496,12 +504,6 @@ public void UnsafeLoadFrom_SamePath_ReturnsEqualAssemblies() Assert.Equal(assembly1, assembly2); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))] - public void LoadFrom_WithHashValue_ThrowsNotSupportedException() - { - Assert.Throws(() => Assembly.LoadFrom(DestTestAssemblyPath, new byte[0], Configuration.Assemblies.AssemblyHashAlgorithm.None)); - } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))] public void LoadModule() { From cf391592bf7faa91952b23af9e07b46d5000f3fa Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 17 May 2024 09:15:28 -0700 Subject: [PATCH 5/6] Update src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml --- .../System.Private.CoreLib/src/CompatibilitySuppressions.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index a9e29a605e36bb..770514a671adfc 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -865,4 +865,4 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - \ No newline at end of file + From dbd54ea9c8c2197dc9f59d60d16b4fe89a66719f Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 17 May 2024 09:15:46 -0700 Subject: [PATCH 6/6] Update src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml --- src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml index bce808f1690e4b..8e96fb8cbaa781 100644 --- a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -32,4 +32,4 @@ CP0015 M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - \ No newline at end of file +