From 4e043ebe75da906aa07f560b0b9aa57793f75a52 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Wed, 5 Apr 2023 20:42:04 +0200 Subject: [PATCH 1/2] Reduce the trim requirements on MetadataUpdateHandlerAttribute --- .../Reflection/Metadata/MetadataUpdateHandlerAttribute.cs | 4 ++-- .../System.Runtime.Loader/ref/System.Runtime.Loader.cs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdateHandlerAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdateHandlerAttribute.cs index c66473df6f93d..b124ca3deb953 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdateHandlerAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdateHandlerAttribute.cs @@ -28,11 +28,11 @@ public sealed class MetadataUpdateHandlerAttribute : Attribute { /// Initializes the attribute. /// A type that handles metadata updates and that should be notified when any occur. - public MetadataUpdateHandlerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type handlerType) => + public MetadataUpdateHandlerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type handlerType) => HandlerType = handlerType; /// Gets the type that handles metadata updates and that should be notified when any occur. - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] public Type HandlerType { get; } } } diff --git a/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs b/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs index a6ab1de1524fd..e5c08f6132c8e 100644 --- a/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs +++ b/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs @@ -4,6 +4,8 @@ // Changes to this file must follow the https://aka.ms/api-review process. // ------------------------------------------------------------------------------ +using System.Diagnostics.CodeAnalysis; + namespace System.Reflection.Metadata { public static partial class AssemblyExtensions @@ -19,8 +21,8 @@ public static partial class MetadataUpdater [System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = true)] public sealed class MetadataUpdateHandlerAttribute : System.Attribute { - public MetadataUpdateHandlerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type handlerType) { } - [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] + public MetadataUpdateHandlerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods)] System.Type handlerType) { } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods)] public System.Type HandlerType { get { throw null; } } } } From fa84db5b40139755621f72a8ad0f62994e70e0e9 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Thu, 6 Apr 2023 23:32:58 +0200 Subject: [PATCH 2/2] add compatibility warning suppression --- .../ApiCompatBaseline.NetCoreAppLatestStable.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.xml b/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.xml index d71ecb2355a24..f744ff4c19376 100644 --- a/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.xml +++ b/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.xml @@ -2761,6 +2761,18 @@ net7.0/System.Linq.Queryable.dll net8.0/System.Linq.Queryable.dll + + CP0015 + M:System.Reflection.Metadata.MetadataUpdateHandlerAttribute.#ctor(System.Type)$0:[T:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute] + net7.0/System.Runtime.Loader.dll + net8.0/System.Runtime.Loader.dll + + + CP0015 + P:System.Reflection.Metadata.MetadataUpdateHandlerAttribute.HandlerType:[T:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute] + net7.0/System.Runtime.Loader.dll + net8.0/System.Runtime.Loader.dll + CP0015 M:System.Runtime.Serialization.Formatter.Deserialize(System.IO.Stream):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute]