diff --git a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs
index ae1f677c25637..295d381439468 100644
--- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs
+++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs
@@ -145,6 +145,7 @@ public enum EventOpcode
Send = 9,
Receive = 240,
}
+ [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public partial class EventSource : System.IDisposable
{
protected EventSource() { }
diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml
index 0dc3b55fc8603..5b8326f6ff097 100644
--- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml
+++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml
@@ -49,12 +49,6 @@
member
M:Internal.Runtime.InteropServices.ComponentActivator.InternalGetFunctionPointer(System.Runtime.Loader.AssemblyLoadContext,System.String,System.String,System.IntPtr)
-
- ILLink
- IL2072
- member
- M:System.Diagnostics.Tracing.EventSource.EnsureDescriptorsInitialized
-
ILLink
IL2075
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
index ff9278b4a49eb..398b1f9a128b2 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
@@ -227,6 +227,11 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute
/// }
///
///
+#if !ES_BUILD_STANDALONE
+ // The EnsureDescriptorsInitialized() method might need to access EventSource and its derived type
+ // members and the trimmer ensures that these members are preserved.
+ [DynamicallyAccessedMembers(ManifestMemberTypes)]
+#endif
public partial class EventSource : IDisposable
{
@@ -2765,7 +2770,16 @@ private void EnsureDescriptorsInitialized()
{
// get the metadata via reflection.
Debug.Assert(m_rawManifest == null);
+#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
+ Justification = "Based on the annotation on EventSource class, Trimmer will see from its analysis members " +
+ "that are marked with RequiresUnreferencedCode and will warn." +
+ "This method will not access any of these members and is safe to call.")]
+ byte[]? GetCreateManifestAndDescriptorsViaLocalMethod(string name) => CreateManifestAndDescriptors(this.GetType(), name, this);
+ m_rawManifest = GetCreateManifestAndDescriptorsViaLocalMethod(Name);
+#else
m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this);
+#endif
Debug.Assert(m_eventData != null);
// TODO Enforce singleton pattern