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 0883ff244559c5..c7905dd7141c63 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml
@@ -964,8 +964,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
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 ba669fa717a1a9..b5a91ab8037fe8 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, Message = "{0} returned {1}.")]
public void OperationReturnedSomething(string operation, Interop.SECURITY_STATUS errorCode) =>
WriteEvent(OperationReturnedSomethingId, operation, errorCode);
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 245a1e6e76ba79..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,40 +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.")]
+ 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.")]
+ 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.")]
+ 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.")]
+ 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.")]
+ 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);
@@ -130,8 +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.")]
+ 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 ?? "");
@@ -140,8 +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.")]
+ 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 ?? "");
@@ -160,8 +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.")]
+ 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 ?? "");
@@ -192,8 +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.")]
+ 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);
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 dacf67b8841e3b..f4a06e51691b0c 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,41 @@ 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;
+
+ [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
{
private int _dummyPrimitive;
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