From 058a46bfd7944e036b05200ce2b91739405ff8a6 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Tue, 21 Mar 2023 14:30:52 -0700 Subject: [PATCH 01/12] Add overload for EventSource primitives I've seen a lot of calls to the varargs EventSource overload that have to manually suppress the trim warning because they only use primitive types. Adding this overload solves two problems: 1. Users won't get a warning if their usage is safe. 2. Users won't have to suppress a warning. --- .../ref/System.Diagnostics.Tracing.cs | 11 ++++++ .../System/Diagnostics/Tracing/EventSource.cs | 39 +++++++++++++++++++ 2 files changed, 50 insertions(+) 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 295d3814394685..eb8c7c95d26e27 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -191,6 +191,7 @@ protected void WriteEvent(int eventId, long arg1, byte[]? arg2) { } protected void WriteEvent(int eventId, long arg1, long arg2) { } protected void WriteEvent(int eventId, long arg1, long arg2, long arg3) { } protected void WriteEvent(int eventId, long arg1, string? arg2) { } + protected void WriteEvent(int eventId, params EventSourcePrimitive[] args) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")] protected void WriteEvent(int eventId, params object?[] args) { } protected void WriteEvent(int eventId, string? arg1) { } @@ -216,6 +217,16 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Gu [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")] public void Write<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] T>(string? eventName, T data) { } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly struct EventSourcePrimitive + { + public static implicit operator EventSourcePrimitive(bool value) => throw null; + public static implicit operator EventSourcePrimitive(byte value) => throw null; + public static implicit operator EventSourcePrimitive(short value) => throw null; + public static implicit operator EventSourcePrimitive(int value) => throw null; + public static implicit operator EventSourcePrimitive(long value) => throw null; + public static implicit operator EventSourcePrimitive(string? value) => throw null; + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] protected internal partial struct EventData { private int _dummyPrimitive; 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 cdadc679a50063..77bda7cf66852e 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 @@ -165,6 +165,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.IO; using System.Numerics; using System.Reflection; using System.Resources; @@ -1126,6 +1127,22 @@ protected unsafe void WriteEvent(int eventId, long arg1, byte[]? arg2) #pragma warning restore 1591 + public readonly struct EventSourcePrimitive + { + internal readonly object? Value; + + private EventSourcePrimitive(object? value) + { + Value = value; + } + public static implicit operator EventSourcePrimitive(bool value) => new(value); + public static implicit operator EventSourcePrimitive(byte value) => new(value); + public static implicit operator EventSourcePrimitive(short value) => new(value); + public static implicit operator EventSourcePrimitive(int value) => new(value); + public static implicit operator EventSourcePrimitive(long value) => new(value); + public static implicit operator EventSourcePrimitive(string? value) => new(value); + } + /// /// Used to construct the data structure to be passed to the native ETW APIs - EventWrite and EventWriteTransfer. /// @@ -1334,6 +1351,28 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel } } + /// + /// This is a varargs helper for writing an event. It does create an array and box all the arguments so it is + /// relatively inefficient and should only be used for relatively rare events (e.g. less than 100 / sec). If your + /// rates are faster than that you should use to create fast helpers for your particular + /// method signature. Even if you use this for rare events, this call should be guarded by an + /// check so that the varargs call is not made when the EventSource is not active. + /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] + protected void WriteEvent(int eventId, params EventSourcePrimitive[] args) + { + var argValues = new object?[args.Length]; + for (int i = 0; i < args.Length; i++) + { + argValues[i] = args[i].Value; + } + unsafe + { + WriteEventVarargs(eventId, null, argValues); + } + } + // fallback varags helpers. /// /// This is the varargs helper for writing an event. It does create an array and box all the arguments so it is From dc1fef041e059c99dc595d739b3635526f2f0ad9 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 22 Mar 2023 11:25:26 -0700 Subject: [PATCH 02/12] Remove unused suppressions in MetricsEventSource --- .../Diagnostics/Metrics/MetricsEventSource.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs index 79a5b78633923b..872efafa22ff55 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs @@ -103,24 +103,18 @@ public void CollectionStop(string sessionId, DateTime intervalStartTime, DateTim } [Event(4, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void CounterRateValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string rate) { WriteEvent(4, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, rate); } [Event(5, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void GaugeValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string lastValue) { WriteEvent(5, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, lastValue); } [Event(6, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void HistogramValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string quantiles) { WriteEvent(6, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, quantiles); @@ -130,8 +124,6 @@ public void HistogramValuePublished(string sessionId, string meterName, string? // or because an instrument matching the pre-existing filter has just been created. This event precedes all *MetricPublished events // for the same named instrument. [Event(7, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void BeginInstrumentReporting(string sessionId, string meterName, string? meterVersion, string instrumentName, string instrumentType, string? unit, string? description) { WriteEvent(7, sessionId, meterName, meterVersion ?? "", instrumentName, instrumentType, unit ?? "", description ?? ""); @@ -140,8 +132,6 @@ public void BeginInstrumentReporting(string sessionId, string meterName, string? // Sent when we stop monitoring the value of a intrument, either because new session filter arguments changed subscriptions // or because the Meter has been disposed. [Event(8, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void EndInstrumentReporting(string sessionId, string meterName, string? meterVersion, string instrumentName, string instrumentType, string? unit, string? description) { WriteEvent(8, sessionId, meterName, meterVersion ?? "", instrumentName, instrumentType, unit ?? "", description ?? ""); @@ -160,8 +150,6 @@ public void InitialInstrumentEnumerationComplete(string sessionId) } [Event(11, Keywords = Keywords.InstrumentPublishing)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void InstrumentPublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string instrumentType, string? unit, string? description) { WriteEvent(11, sessionId, meterName, meterVersion ?? "", instrumentName, instrumentType, unit ?? "", description ?? ""); @@ -192,8 +180,6 @@ public void MultipleSessionsNotSupportedError(string runningSessionId) } [Event(16, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void UpDownCounterRateValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string rate) { WriteEvent(16, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, rate); From 6ad50d9fa7ccd8c8036bfca33ed33b20f9814e7e Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 22 Mar 2023 11:40:31 -0700 Subject: [PATCH 03/12] Add doc comments for EventSourcePrimitive --- .../src/System/Diagnostics/Tracing/EventSource.cs | 5 +++++ 1 file changed, 5 insertions(+) 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 77bda7cf66852e..8ea7bd927e2ef1 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 @@ -1127,6 +1127,11 @@ protected unsafe void WriteEvent(int eventId, long arg1, byte[]? arg2) #pragma warning restore 1591 + /// + /// A wrapper type for separating primitive types (int, long, string, etc) from other types + /// in the EventSource API. This type shouldn't be used directly, but just as implicit conversions + /// when using the WriteEvent API. + /// public readonly struct EventSourcePrimitive { internal readonly object? Value; From 6b0def3b53cf0857a0fdd74266329f7099a1576d Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 22 Mar 2023 12:57:28 -0700 Subject: [PATCH 04/12] Remove suppressions from TransactionsEtwProvider --- .../src/System/Transactions/TransactionsEtwProvider.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs index f9d4e77006ff0b..12555bbecc4eb4 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs @@ -573,7 +573,6 @@ internal void EnlistmentCreated(TraceSourceType traceSource, EnlistmentTraceIden } [Event(ENLISTMENT_CREATED_LTM_EVENTID, Keywords = Keywords.TraceLtm, Level = EventLevel.Informational, Task = Tasks.Enlistment, Opcode = Opcodes.Create, Message = "Enlistment Created (LTM). ID is {0}, type is {1}, options is {2}")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Only string/int are passed")] private void EnlistmentCreatedLtm(int enlistmentIdentifier, string enlistmentType, string enlistmentOptions) { SetActivityId(string.Empty); @@ -581,7 +580,6 @@ private void EnlistmentCreatedLtm(int enlistmentIdentifier, string enlistmentTyp } [Event(ENLISTMENT_CREATED_OLETX_EVENTID, Keywords = Keywords.TraceOleTx, Level = EventLevel.Informational, Task = Tasks.Enlistment, Opcode = Opcodes.Create, Message = "Enlistment Created (OLETX). ID is {0}, type is {1}, options is {2}")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Only string/int are passed")] private void EnlistmentCreatedOleTx(int enlistmentIdentifier, string enlistmentType, string enlistmentOptions) { SetActivityId(string.Empty); From 1a5101c477cd383942270449021280aaf5e74f80 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 24 Mar 2023 12:33:19 -0700 Subject: [PATCH 05/12] Remove guidance around warning suppression, as the safe primitives should no longer produce warnings --- .../Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs index 6619ca770bbd1d..1c0f692631174e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs @@ -24,7 +24,7 @@ public partial class EventSource #if FEATURE_MANAGED_ETW private byte[]? m_providerMetadata; private protected virtual ReadOnlySpan ProviderMetadata => m_providerMetadata; - private const string EventSourceRequiresUnreferenceMessage = "EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type"; + private const string EventSourceRequiresUnreferenceMessage = "EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed."; private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; #endif From b9d9e26d4b8729a9832a0d5efc41d0e3ca684f5c Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 30 Mar 2023 13:21:18 -0700 Subject: [PATCH 06/12] Add tests --- .../EventSourcePropertyValueTest.cs | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourcePropertyValueTest.cs b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourcePropertyValueTest.cs index a7e0db64cb1ae4..6682cb0fd45eb8 100644 --- a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourcePropertyValueTest.cs +++ b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourcePropertyValueTest.cs @@ -40,15 +40,37 @@ public void LogData(TestData data) } } + [EventSource(Name = EventSourceName)] + private class PrimitiveOnlyEventSource : EventSource + { + public const string EventSourceName = "PrimitiveOnly"; + public readonly static PrimitiveOnlyEventSource Log = new PrimitiveOnlyEventSource(); + + [Event(1)] + public void LogBoolInt(bool b1, int i1) + { + WriteEvent(1, b1, i1); + } + + [Event(2)] + public void LogStringIntStringInt(string s1, int i1, string s2, int i2) + { + WriteEvent(2, s1, i1, s2, i2); + } + } + private class TestEventListener : EventListener { public ReadOnlyCollection LogDataPayload { get; set; } protected override void OnEventSourceCreated(EventSource eventSource) { - if (eventSource.Name == TestEventSource.EventSourceName) + switch (eventSource.Name) { - EnableEvents(eventSource, EventLevel.Verbose); + case TestEventSource.EventSourceName: + case PrimitiveOnlyEventSource.EventSourceName: + EnableEvents(eventSource, EventLevel.Verbose); + break; } base.OnEventSourceCreated(eventSource); @@ -56,11 +78,7 @@ protected override void OnEventSourceCreated(EventSource eventSource) protected override void OnEventWritten(EventWrittenEventArgs eventData) { - if (eventData.EventName == "LogData") - { - LogDataPayload = eventData.Payload; - } - + LogDataPayload = eventData.Payload; base.OnEventWritten(eventData); } } @@ -79,14 +97,23 @@ public static int Main() }; TestEventSource.Log.LogData(testData); - if (listener.LogDataPayload?.Count == 2 && - (int)listener.LogDataPayload[0] == testData.TestInt && - (int)((IDictionary)listener.LogDataPayload[1])["SubInt"] == testData.SubData.SubInt) + if (listener.LogDataPayload?.Count != 2 || + (int)listener.LogDataPayload[0] != testData.TestInt || + (int)((IDictionary)listener.LogDataPayload[1])["SubInt"] != testData.SubData.SubInt) { - return 100; + return -1; } - return -1; + PrimitiveOnlyEventSource.Log.LogStringIntStringInt("a", 1, "b", 2); + if (listener.LogDataPayload?.Count != 4 || + (string)listener.LogDataPayload[0] != "a" || + (int)listener.LogDataPayload[1] != 1 || + (string)listener.LogDataPayload[2] != "b" || + (int)listener.LogDataPayload[3] != 2) + { + return -2; + } } + return 100; } } From 2d79faaaf33c749aaf6758e2e483a1230ad6afe7 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 30 Mar 2023 13:42:55 -0700 Subject: [PATCH 07/12] API compat suppressions --- .../CompatibilitySuppressions.xml | 42 ++++++++++++++++++ .../src/CompatibilitySuppressions.xml | 44 ++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml index 6a201651f126a8..276be3a543e343 100644 --- a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -1,3 +1,45 @@  + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,System.Guid@,System.Guid@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEvent(System.Int32,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventCore(System.Int32,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityId(System.Int32,System.Guid,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.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 529449f22e2bad..d7381ef3c99ff6 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -972,8 +972,50 @@ CP0014 M:System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(System.Object)->object?:[T:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute] + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,System.Guid@,System.Guid@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEvent(System.Int32,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventCore(System.Int32,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityId(System.Int32,System.Guid,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + CP0016 M:System.Runtime.InteropServices.Marshal.GetObjectForNativeVariant``1(System.IntPtr)->T?:[T:System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - + \ No newline at end of file From 9d0e72059a719fe1aa0f054cb3dc34228a5f4371 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 30 Mar 2023 16:29:01 -0700 Subject: [PATCH 08/12] Add suppression for Mono --- .../CompatibilitySuppressions.xml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml index 6836172aa2e687..ed9aefadda0057 100644 --- a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml +++ b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml @@ -4,4 +4,46 @@ CP0014 M:System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(System.Object)->object?:[T:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute] + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,System.Guid@,System.Guid@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEvent(System.Int32,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventCore(System.Int32,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityId(System.Int32,System.Guid,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + + + CP0015 + M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] + ref/net8.0/System.Private.CoreLib.dll + lib/net8.0/System.Private.CoreLib.dll + \ No newline at end of file From 9457427c305e04583ec2c4d1fb0b0393ce6cacf8 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 27 Apr 2023 15:24:17 -0700 Subject: [PATCH 09/12] Add remaining overloads as described in API review --- .../Diagnostics/Metrics/MetricsEventSource.cs | 4 --- .../ref/System.Diagnostics.Tracing.cs | 25 +++++++++++++++++++ .../System/Diagnostics/Tracing/EventSource.cs | 25 +++++++++++++++++++ .../System/Threading/Tasks/TplEventSource.cs | 2 -- .../OpenSslX509ChainEventSource.cs | 6 ----- .../src/Internal/DataflowEtwProvider.cs | 4 --- .../Transactions/TransactionsEtwProvider.cs | 2 -- 7 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs index 872efafa22ff55..95c5218c639390 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs @@ -87,16 +87,12 @@ public void Message(string? Message) } [Event(2, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void CollectionStart(string sessionId, DateTime intervalStartTime, DateTime intervalEndTime) { WriteEvent(2, sessionId, intervalStartTime, intervalEndTime); } [Event(3, Keywords = Keywords.TimeSeriesValues)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] public void CollectionStop(string sessionId, DateTime intervalStartTime, DateTime intervalEndTime) { WriteEvent(3, sessionId, intervalStartTime, intervalEndTime); 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 eb8c7c95d26e27..c01ac8c9230967 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -224,7 +224,32 @@ public readonly struct EventSourcePrimitive public static implicit operator EventSourcePrimitive(short value) => throw null; public static implicit operator EventSourcePrimitive(int value) => throw null; public static implicit operator EventSourcePrimitive(long value) => throw null; + + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(sbyte value) => throw null; + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(ushort value) => throw null; + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(uint value) => throw null; + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(ulong value) => throw null; + [CLSCompliant(false)] + // Added to prevent going through the nuint -> ulong conversion + public static implicit operator EventSourcePrimitive(nuint value) => throw null; + + public static implicit operator EventSourcePrimitive(float value) => throw null; + public static implicit operator EventSourcePrimitive(double value) => throw null; + public static implicit operator EventSourcePrimitive(decimal value) => throw null; + public static implicit operator EventSourcePrimitive(string? value) => throw null; + public static implicit operator EventSourcePrimitive(byte[]? value) => throw null; + + public static implicit operator EventSourcePrimitive(Guid value) => throw null; + public static implicit operator EventSourcePrimitive(DateTime value) => throw null; + public static implicit operator EventSourcePrimitive(nint value) => throw null; + public static implicit operator EventSourcePrimitive(char value) => throw null; + + public static implicit operator EventSourcePrimitive(Enum value) => throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] protected internal partial struct EventData 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 8ea7bd927e2ef1..01206566b56ac7 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 @@ -1145,7 +1145,32 @@ private EventSourcePrimitive(object? value) public static implicit operator EventSourcePrimitive(short value) => new(value); public static implicit operator EventSourcePrimitive(int value) => new(value); public static implicit operator EventSourcePrimitive(long value) => new(value); + + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(sbyte value) => new(value); + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(ushort value) => new(value); + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(uint value) => new(value); + [CLSCompliant(false)] + public static implicit operator EventSourcePrimitive(ulong value) => new(value); + [CLSCompliant(false)] + // Added to prevent going through the nuint -> ulong conversion + public static implicit operator EventSourcePrimitive(nuint value) => new(value); + + public static implicit operator EventSourcePrimitive(float value) => new(value); + public static implicit operator EventSourcePrimitive(double value) => new(value); + public static implicit operator EventSourcePrimitive(decimal value) => new(value); + public static implicit operator EventSourcePrimitive(string? value) => new(value); + public static implicit operator EventSourcePrimitive(byte[]? value) => new(value); + + public static implicit operator EventSourcePrimitive(Guid value) => new(value); + public static implicit operator EventSourcePrimitive(DateTime value) => new(value); + public static implicit operator EventSourcePrimitive(nint value) => new(value); + public static implicit operator EventSourcePrimitive(char value) => new(value); + + public static implicit operator EventSourcePrimitive(Enum value) => new(value); } /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs index 0af37f81aacabe..aae2eb149918c7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs @@ -527,8 +527,6 @@ public void RunningContinuationList(int TaskID, int Index, long Object) [Event(24, Keywords = Keywords.Debug)] public void DebugFacilityMessage1(string Facility, string Message, string Value1) { WriteEvent(24, Facility, Message, Value1); } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", - Justification = "Guid parameter is safe with WriteEvent")] [Event(25, Keywords = Keywords.DebugActivityId)] public void SetActivityId(Guid NewId) { diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs index b8b105197980a5..0e1cdc25efb832 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs @@ -478,8 +478,6 @@ internal void CrlCacheDecodeError() EventId_CrlCacheExpired, Level = EventLevel.Verbose, Message = "The cached CRL's nextUpdate value ({1:O}) is not after the verification time ({0:O}).")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "verificationTime and nextUpdate are DateTime values, which are trimmer safe")] internal void CrlCacheExpired(DateTime verificationTime, DateTime nextUpdate) { if (IsEnabled()) @@ -504,8 +502,6 @@ internal void CrlCacheFileBasedExpiry() EventId_CrlCacheAcceptedFile, Level = EventLevel.Verbose, Message = "The cached crl nextUpdate value ({0:O}) is acceptable, using the cached file.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "nextUpdate is a DateTime value, which is trimmer safe")] internal void CrlCacheAcceptedFile(DateTime nextUpdate) { if (IsEnabled()) @@ -707,8 +703,6 @@ private void CachingIntermediateFailed() Message = "Starting revocation check in mode '{0}' with scope '{1}' on a {2}-element chain.", Opcode = EventOpcode.Start, Level = EventLevel.Informational)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "revocationMode and revocationFlag are enums, and are trimmer safe")] internal void RevocationCheckStart(X509RevocationMode revocationMode, X509RevocationFlag revocationFlag, int chainSize) { if (IsEnabled()) diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs index 51560f24e56bbb..8f0f0c71ab8f23 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs @@ -102,8 +102,6 @@ internal void TaskLaunchedForMessageHandling( } } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "WriteEvent Parameters are trimmer safe")] [Event(TASKLAUNCHED_EVENTID, Level = EventLevel.Informational)] private void TaskLaunchedForMessageHandling(int blockId, TaskLaunchedReason reason, int availableMessages, int taskId) { @@ -159,8 +157,6 @@ internal enum BlockCompletionReason Canceled = (int)TaskStatus.Canceled } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "WriteEvent Parameters are trimmer safe")] [Event(BLOCKCOMPLETED_EVENTID, Level = EventLevel.Informational)] private void DataflowBlockCompleted(int blockId, BlockCompletionReason reason, string exceptionData) { diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs index 12555bbecc4eb4..7964dd4a60eb87 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs @@ -1055,8 +1055,6 @@ internal void TransactionScopeCreated(TransactionTraceIdentifier transactionID, } } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "TransactionScopeResult parameter is an enum and is trimmer safe")] [Event(TRANSACTIONSCOPE_CREATED_EVENTID, Keywords = Keywords.TraceBase, Level = EventLevel.Informational, Task = Tasks.TransactionScope, Opcode = Opcodes.Created, Message = "Transactionscope was created: Transaction ID is {0}, TransactionScope Result is {1}")] private void TransactionScopeCreated(string transactionID, TransactionScopeResult transactionScopeResult) { From a46ea126e1eb0da80b0033743aaf9ac561f11fc4 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 19 May 2023 15:09:45 -0700 Subject: [PATCH 10/12] Suppress warnings on TFMs < 8.0 --- .../Diagnostics/Metrics/MetricsEventSource.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs index 478d43acb1c3d9..85231812401a3b 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs @@ -87,30 +87,50 @@ public void Message(string? Message) } [Event(2, Keywords = Keywords.TimeSeriesValues)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void CollectionStart(string sessionId, DateTime intervalStartTime, DateTime intervalEndTime) { WriteEvent(2, sessionId, intervalStartTime, intervalEndTime); } [Event(3, Keywords = Keywords.TimeSeriesValues)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void CollectionStop(string sessionId, DateTime intervalStartTime, DateTime intervalEndTime) { WriteEvent(3, sessionId, intervalStartTime, intervalEndTime); } [Event(4, Keywords = Keywords.TimeSeriesValues, Version=1)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void CounterRateValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string rate, string value) { WriteEvent(4, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, rate, value); } [Event(5, Keywords = Keywords.TimeSeriesValues)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void GaugeValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string lastValue) { WriteEvent(5, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, lastValue); } [Event(6, Keywords = Keywords.TimeSeriesValues, Version=1)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void HistogramValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string quantiles, int count, double sum) { WriteEvent(6, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, quantiles, count, sum); @@ -120,6 +140,10 @@ public void HistogramValuePublished(string sessionId, string meterName, string? // or because an instrument matching the pre-existing filter has just been created. This event precedes all *MetricPublished events // for the same named instrument. [Event(7, Keywords = Keywords.TimeSeriesValues)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void BeginInstrumentReporting(string sessionId, string meterName, string? meterVersion, string instrumentName, string instrumentType, string? unit, string? description) { WriteEvent(7, sessionId, meterName, meterVersion ?? "", instrumentName, instrumentType, unit ?? "", description ?? ""); @@ -128,6 +152,10 @@ public void BeginInstrumentReporting(string sessionId, string meterName, string? // Sent when we stop monitoring the value of a intrument, either because new session filter arguments changed subscriptions // or because the Meter has been disposed. [Event(8, Keywords = Keywords.TimeSeriesValues)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void EndInstrumentReporting(string sessionId, string meterName, string? meterVersion, string instrumentName, string instrumentType, string? unit, string? description) { WriteEvent(8, sessionId, meterName, meterVersion ?? "", instrumentName, instrumentType, unit ?? "", description ?? ""); @@ -146,6 +174,10 @@ public void InitialInstrumentEnumerationComplete(string sessionId) } [Event(11, Keywords = Keywords.InstrumentPublishing)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void InstrumentPublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string instrumentType, string? unit, string? description) { WriteEvent(11, sessionId, meterName, meterVersion ?? "", instrumentName, instrumentType, unit ?? "", description ?? ""); @@ -176,6 +208,10 @@ public void MultipleSessionsNotSupportedError(string runningSessionId) } [Event(16, Keywords = Keywords.TimeSeriesValues, Version=1)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif public void UpDownCounterRateValuePublished(string sessionId, string meterName, string? meterVersion, string instrumentName, string? unit, string tags, string rate, string value) { WriteEvent(16, sessionId, meterName, meterVersion ?? "", instrumentName, unit ?? "", tags, rate, value); From 004cc810f651ebbc0f22194274605468c4c28c45 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 19 May 2023 15:27:09 -0700 Subject: [PATCH 11/12] Add suppressions for System.Thread.Tasks.Dataflow --- .../src/Internal/DataflowEtwProvider.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs index 8f0f0c71ab8f23..2e40fb2a105b48 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs @@ -103,6 +103,10 @@ internal void TaskLaunchedForMessageHandling( } [Event(TASKLAUNCHED_EVENTID, Level = EventLevel.Informational)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif private void TaskLaunchedForMessageHandling(int blockId, TaskLaunchedReason reason, int availableMessages, int taskId) { WriteEvent(TASKLAUNCHED_EVENTID, blockId, reason, availableMessages, taskId); @@ -158,6 +162,10 @@ internal enum BlockCompletionReason } [Event(BLOCKCOMPLETED_EVENTID, Level = EventLevel.Informational)] +#if !NET8_0_OR_GREATER + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "This calls WriteEvent with all primitive arguments which is safe. Primitives are always serialized properly.")] +#endif private void DataflowBlockCompleted(int blockId, BlockCompletionReason reason, string exceptionData) { WriteEvent(BLOCKCOMPLETED_EVENTID, blockId, reason, exceptionData); From 561ca3590a70bbeb11abf8b0e1718f3f32610efd Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 19 May 2023 16:18:08 -0700 Subject: [PATCH 12/12] Remove suppressions --- .../System/Net/Security/NetEventSource.Security.Windows.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libraries/Common/src/System/Net/Security/NetEventSource.Security.Windows.cs b/src/libraries/Common/src/System/Net/Security/NetEventSource.Security.Windows.cs index c1bad7d5963db6..e8756a17883a87 100644 --- a/src/libraries/Common/src/System/Net/Security/NetEventSource.Security.Windows.cs +++ b/src/libraries/Common/src/System/Net/Security/NetEventSource.Security.Windows.cs @@ -28,8 +28,6 @@ public void EnumerateSecurityPackages(string? securityPackage) => public void SspiPackageNotFound(string packageName) => WriteEvent(SspiPackageNotFoundId, packageName); - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "parameter intent is an enum and is trimmer safe")] [Event(AcquireDefaultCredentialId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void AcquireDefaultCredential(string packageName, Interop.SspiCli.CredentialUse intent) => WriteEvent(AcquireDefaultCredentialId, packageName, intent); @@ -58,8 +56,6 @@ public void AcceptSecurityContext(SafeFreeCredentials? credential, SafeDeleteCon private void AcceptSecurityContext(string credential, string context, Interop.SspiCli.ContextFlags inFlags) => WriteEvent(AcceptSecuritContextId, credential, context, (int)inFlags); - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "parameter errorCode is an enum and is trimmer safe")] [Event(OperationReturnedSomethingId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void OperationReturnedSomething(string operation, Interop.SECURITY_STATUS errorCode) => WriteEvent(OperationReturnedSomethingId, operation, errorCode);