From 54516c728350ec926dab40658fe67cef5f94c7b9 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 29 Oct 2020 05:18:01 -0700 Subject: [PATCH 01/24] eh fix --- .../src/binder/clrprivbindercoreclr.cpp | 98 +++++++++---------- .../BinderTracingTest.EventHandlers.cs | 12 ++- .../BinderTracingTest.ResolutionFlow.cs | 7 +- 3 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/coreclr/src/binder/clrprivbindercoreclr.cpp b/src/coreclr/src/binder/clrprivbindercoreclr.cpp index 292ad99fd8554..571e127d7dab2 100644 --- a/src/coreclr/src/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/src/binder/clrprivbindercoreclr.cpp @@ -49,76 +49,72 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(IAssemblyName *pIAssemblyNa HRESULT hr = S_OK; VALIDATE_ARG_RET(pIAssemblyName != nullptr && ppAssembly != nullptr); - EX_TRY - { - *ppAssembly = nullptr; + *ppAssembly = nullptr; - ReleaseHolder pCoreCLRFoundAssembly; - ReleaseHolder pAssemblyName; + ReleaseHolder pCoreCLRFoundAssembly; + ReleaseHolder pAssemblyName; - SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(pIAssemblyName)); + SAFE_NEW(pAssemblyName, AssemblyName); + IF_FAIL_GO(pAssemblyName->Init(pIAssemblyName)); - hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, false /* excludeAppPaths */); + hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, false /* excludeAppPaths */); #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) - if ((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || - (hr == FUSION_E_APP_DOMAIN_LOCKED) || (hr == FUSION_E_REF_DEF_MISMATCH)) + if ((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || + (hr == FUSION_E_APP_DOMAIN_LOCKED) || (hr == FUSION_E_REF_DEF_MISMATCH)) + { + // If we are here, one of the following is possible: + // + // 1) The assembly has not been found in the current binder's application context (i.e. it has not already been loaded), OR + // 2) An assembly with the same simple name was already loaded in the context of the current binder but we ran into a Ref/Def + // mismatch (either due to version difference or strong-name difference). + // + // Attempt to resolve the assembly via managed ALC instance. This can either fail the bind or return reference to an existing + // assembly that has been loaded + INT_PTR pManagedAssemblyLoadContext = GetManagedAssemblyLoadContext(); + if (pManagedAssemblyLoadContext == NULL) { - // If we are here, one of the following is possible: - // - // 1) The assembly has not been found in the current binder's application context (i.e. it has not already been loaded), OR - // 2) An assembly with the same simple name was already loaded in the context of the current binder but we ran into a Ref/Def - // mismatch (either due to version difference or strong-name difference). - // - // Attempt to resolve the assembly via managed ALC instance. This can either fail the bind or return reference to an existing - // assembly that has been loaded - INT_PTR pManagedAssemblyLoadContext = GetManagedAssemblyLoadContext(); - if (pManagedAssemblyLoadContext == NULL) + // For satellite assemblies, the managed ALC has additional resolution logic (defined by the runtime) which + // should be run even if the managed default ALC has not yet been used. (For non-satellite assemblies, any + // additional logic comes through a user-defined event handler which would have initialized the managed ALC, + // so if the managed ALC is not set yet, there is no additional logic to run) + SString &culture = pAssemblyName->GetCulture(); + if (!culture.IsEmpty() && !culture.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral)) { - // For satellite assemblies, the managed ALC has additional resolution logic (defined by the runtime) which - // should be run even if the managed default ALC has not yet been used. (For non-satellite assemblies, any - // additional logic comes through a user-defined event handler which would have initialized the managed ALC, - // so if the managed ALC is not set yet, there is no additional logic to run) - SString &culture = pAssemblyName->GetCulture(); - if (!culture.IsEmpty() && !culture.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral)) - { - // Make sure the managed default ALC is initialized. - GCX_COOP(); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__INITIALIZE_DEFAULT_CONTEXT); - DECLARE_ARGHOLDER_ARRAY(args, 0); - CALL_MANAGED_METHOD_NORET(args) - - pManagedAssemblyLoadContext = GetManagedAssemblyLoadContext(); - _ASSERTE(pManagedAssemblyLoadContext != NULL); - } + // Make sure the managed default ALC is initialized. + GCX_COOP(); + PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__INITIALIZE_DEFAULT_CONTEXT); + DECLARE_ARGHOLDER_ARRAY(args, 0); + CALL_MANAGED_METHOD_NORET(args) + + pManagedAssemblyLoadContext = GetManagedAssemblyLoadContext(); + _ASSERTE(pManagedAssemblyLoadContext != NULL); } + } - if (pManagedAssemblyLoadContext != NULL) + if (pManagedAssemblyLoadContext != NULL) + { + hr = AssemblyBinder::BindUsingHostAssemblyResolver(pManagedAssemblyLoadContext, pAssemblyName, pIAssemblyName, + NULL, &pCoreCLRFoundAssembly); + if (SUCCEEDED(hr)) { - hr = AssemblyBinder::BindUsingHostAssemblyResolver(pManagedAssemblyLoadContext, pAssemblyName, pIAssemblyName, - NULL, &pCoreCLRFoundAssembly); - if (SUCCEEDED(hr)) + // We maybe returned an assembly that was bound to a different AssemblyLoadContext instance. + // In such a case, we will not overwrite the binding context (which would be wrong since it would not + // be present in the cache of the current binding context). + if (pCoreCLRFoundAssembly->GetBinder() == NULL) { - // We maybe returned an assembly that was bound to a different AssemblyLoadContext instance. - // In such a case, we will not overwrite the binding context (which would be wrong since it would not - // be present in the cache of the current binding context). - if (pCoreCLRFoundAssembly->GetBinder() == NULL) - { - pCoreCLRFoundAssembly->SetBinder(this); - } + pCoreCLRFoundAssembly->SetBinder(this); } } } + } #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) - IF_FAIL_GO(hr); + IF_FAIL_GO(hr); - *ppAssembly = pCoreCLRFoundAssembly.Extract(); + *ppAssembly = pCoreCLRFoundAssembly.Extract(); Exit:; - } - EX_CATCH_HRESULT(hr); return hr; } diff --git a/src/tests/Loader/binding/tracing/BinderTracingTest.EventHandlers.cs b/src/tests/Loader/binding/tracing/BinderTracingTest.EventHandlers.cs index e9a2073b26d48..89a809a2035ba 100644 --- a/src/tests/Loader/binding/tracing/BinderTracingTest.EventHandlers.cs +++ b/src/tests/Loader/binding/tracing/BinderTracingTest.EventHandlers.cs @@ -13,6 +13,14 @@ namespace BinderTracingTests { + public class BinderTestException : Exception + { + public BinderTestException(string message) + : base(message) + { + } + + } partial class BinderTracingTest { private const string AssemblyLoadFromHandlerName = "LoadFromResolveHandler"; @@ -381,7 +389,7 @@ public void Dispose() private Assembly OnAssemblyLoadContextResolving(AssemblyLoadContext context, AssemblyName assemblyName) { if (handlerReturn == HandlerReturn.Exception) - throw new Exception("Exception in handler for AssemblyLoadContext.Resolving"); + throw new BinderTestException("Exception in handler for AssemblyLoadContext.Resolving"); Assembly asm = ResolveAssembly(context, assemblyName); var invocation = new HandlerInvocation() @@ -403,7 +411,7 @@ private Assembly OnAssemblyLoadContextResolving(AssemblyLoadContext context, Ass private Assembly OnAppDomainAssemblyResolve(object sender, ResolveEventArgs args) { if (handlerReturn == HandlerReturn.Exception) - throw new Exception("Exception in handler for AppDomain.AssemblyResolve"); + throw new BinderTestException("Exception in handler for AppDomain.AssemblyResolve"); var assemblyName = new AssemblyName(args.Name); var customContext = new CustomALC(nameof(OnAppDomainAssemblyResolve)); diff --git a/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs b/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs index 1d56df8068891..2bb37eda7c4bf 100644 --- a/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs +++ b/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs @@ -412,7 +412,7 @@ public static BindOperation AssemblyLoadContextResolvingEvent_CustomALC_Exceptio CustomALC alc = new CustomALC(nameof(AssemblyLoadContextResolvingEvent_CustomALC_Exception)); using (var handlers = new Handlers(HandlerReturn.Exception, alc)) { - Assert.Throws(() => alc.LoadFromAssemblyName(assemblyName)); + Assert.Throws(() => alc.LoadFromAssemblyName(assemblyName)); return new BindOperation() { @@ -442,9 +442,10 @@ public static BindOperation AssemblyLoadContextResolvingEvent_CustomALC_Exceptio public static BindOperation AssemblyLoadContextResolvingEvent_DefaultALC_Exception() { var assemblyName = new AssemblyName(SubdirectoryAssemblyName); + System.Diagnostics.Debugger.Break(); using (var handlers = new Handlers(HandlerReturn.Exception, AssemblyLoadContext.Default)) { - Assert.Throws(() => AssemblyLoadContext.Default.LoadFromAssemblyName(assemblyName)); + Assert.Throws(() => AssemblyLoadContext.Default.LoadFromAssemblyName(assemblyName)); return new BindOperation() { @@ -551,7 +552,7 @@ public static BindOperation AppDomainAssemblyResolveEvent_Exception() CustomALC alc = new CustomALC(nameof(AppDomainAssemblyResolveEvent_Exception)); using (var handlers = new Handlers(HandlerReturn.Exception)) { - Assert.Throws(() => alc.LoadFromAssemblyName(assemblyName)); + Assert.Throws(() => alc.LoadFromAssemblyName(assemblyName)); return new BindOperation() { From 42eadd3dce3adf5cc20c191d17be3856cfe89ad3 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 11 Feb 2021 14:12:43 -0800 Subject: [PATCH 02/24] test change that inadvertently got checked in earlier --- .../Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs b/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs index 2bb37eda7c4bf..4ab8fc377300b 100644 --- a/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs +++ b/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.cs @@ -442,7 +442,6 @@ public static BindOperation AssemblyLoadContextResolvingEvent_CustomALC_Exceptio public static BindOperation AssemblyLoadContextResolvingEvent_DefaultALC_Exception() { var assemblyName = new AssemblyName(SubdirectoryAssemblyName); - System.Diagnostics.Debugger.Break(); using (var handlers = new Handlers(HandlerReturn.Exception, AssemblyLoadContext.Default)) { Assert.Throws(() => AssemblyLoadContext.Default.LoadFromAssemblyName(assemblyName)); From db9be8247e8f4d03a975e450b5d8df342fa09072 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 26 Feb 2021 08:02:40 -0800 Subject: [PATCH 03/24] Suppresses the trimmer warning on TypeAnalysis ctor --- .../NetEventSource.Security.Windows.cs | 7 ++++++ ...System.Diagnostics.DiagnosticSource.csproj | 5 ++++- .../DiagnosticSourceEventSource.cs | 22 +++++++++++++++++-- .../ref/System.Diagnostics.Tracing.cs | 5 +++++ .../NetEventSource.Security.Windows.cs | 5 +++++ .../Diagnostics/Tracing/EventCounter.cs | 3 +++ .../System/Diagnostics/Tracing/EventSource.cs | 6 ++++- .../Tracing/IncrementingEventCounter.cs | 4 ++++ .../Tracing/IncrementingPollingCounter.cs | 4 ++++ .../Diagnostics/Tracing/PollingCounter.cs | 4 ++++ .../TraceLogging/TraceLoggingEventSource.cs | 17 ++++++++++++++ .../Tracing/TraceLogging/TypeAnalysis.cs | 5 +++++ .../System/Threading/Tasks/TplEventSource.cs | 3 +++ .../src/Internal/DataflowEtwProvider.cs | 4 ++++ .../System.Threading.Tasks.Dataflow.csproj | 3 +++ .../Transactions/TransactionsEtwProvider.cs | 3 +++ 16 files changed, 96 insertions(+), 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 cae8f1c24d281..77ef71b94d359 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 @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Net.Security; @@ -8,6 +9,8 @@ namespace System.Net { internal sealed partial class NetEventSource { + [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) { @@ -59,6 +62,8 @@ 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) { @@ -68,6 +73,8 @@ public void OperationReturnedSomething(string operation, Interop.SECURITY_STATUS } } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "parameter errorCode is an enum and is trimmer safe")] [Event(SecurityContextInputBufferId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void SecurityContextInputBuffer(string context, int inputBufferSize, int outputBufferSize, Interop.SECURITY_STATUS errorCode) { diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj index 9634c095f94e0..71a05264bc3d7 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj @@ -84,6 +84,9 @@ + + + @@ -105,4 +108,4 @@ - \ No newline at end of file + diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index b38829b6ad0cb..741e2ec484a96 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -223,6 +223,8 @@ public void Message(string? Message) /// /// Events from DiagnosticSource can be forwarded to EventSource using this event. /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] [Event(2, Keywords = Keywords.Events)] private void Event(string SourceName, string EventName, IEnumerable>? Arguments) { @@ -243,6 +245,8 @@ private void EventJson(string SourceName, string EventName, string ArgmentsJson) /// /// Used to mark the beginning of an activity /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] [Event(4, Keywords = Keywords.Events)] private void Activity1Start(string SourceName, string EventName, IEnumerable> Arguments) { @@ -252,6 +256,8 @@ private void Activity1Start(string SourceName, string EventName, IEnumerable /// Used to mark the end of an activity /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] [Event(5, Keywords = Keywords.Events)] private void Activity1Stop(string SourceName, string EventName, IEnumerable> Arguments) { @@ -261,6 +267,8 @@ private void Activity1Stop(string SourceName, string EventName, IEnumerable /// Used to mark the beginning of an activity /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] [Event(6, Keywords = Keywords.Events)] private void Activity2Start(string SourceName, string EventName, IEnumerable> Arguments) { @@ -270,6 +278,8 @@ private void Activity2Start(string SourceName, string EventName, IEnumerable /// Used to mark the end of an activity that can be recursive. /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] [Event(7, Keywords = Keywords.Events)] private void Activity2Stop(string SourceName, string EventName, IEnumerable> Arguments) { @@ -279,6 +289,8 @@ private void Activity2Stop(string SourceName, string EventName, IEnumerable /// Used to mark the beginning of an activity /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] [Event(8, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)] private void RecursiveActivity1Start(string SourceName, string EventName, IEnumerable> Arguments) { @@ -288,6 +300,8 @@ private void RecursiveActivity1Start(string SourceName, string EventName, IEnume /// /// Used to mark the end of an activity that can be recursive. /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] [Event(9, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)] private void RecursiveActivity1Stop(string SourceName, string EventName, IEnumerable> Arguments) { @@ -311,8 +325,10 @@ private void NewDiagnosticListener(string SourceName) /// The ActivitySource name /// The Activity name /// Name and value pairs of the Activity properties + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] #if NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT - [Event(11, Keywords = Keywords.Events)] + [Event(11, Keywords = Keywords.Events)] #else [Event(11, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)] #endif @@ -325,8 +341,10 @@ private void ActivityStart(string SourceName, string ActivityName, IEnumerableThe ActivitySource name /// The Activity name /// Name and value pairs of the Activity properties + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Arguments parameter is trimmer safe")] #if NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT - [Event(12, Keywords = Keywords.Events)] + [Event(12, Keywords = Keywords.Events)] #else [Event(12, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)] #endif 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 fc020ee31e5ec..07da9b336ef29 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -190,6 +190,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) { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] protected void WriteEvent(int eventId, params object?[] args) { } protected void WriteEvent(int eventId, string? arg1) { } protected void WriteEvent(int eventId, string? arg1, int arg2) { } @@ -202,9 +203,13 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, System.Dia protected void WriteEventWithRelatedActivityId(int eventId, System.Guid relatedActivityId, params object?[] args) { } [System.CLSCompliantAttribute(false)] protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Guid* relatedActivityId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] public void Write(string? eventName, System.Diagnostics.Tracing.EventSourceOptions options, T data) { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] public void Write(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref System.Guid activityId, ref System.Guid relatedActivityId, ref T data) { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] public void Write(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref T data) { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] public void Write(string? eventName, T data) { } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] protected internal partial struct EventData diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs b/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs index 3baef823c78d1..12694700cf8a3 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Net.Security; @@ -8,6 +9,8 @@ namespace System.Net { internal sealed partial class NetEventSource { + [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) { @@ -59,6 +62,8 @@ 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) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs index 2f4489afc9e6c..ce25ed2702389 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs @@ -95,6 +95,9 @@ internal void OnMetricWritten(double value) _count++; } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "CounterPayload type has been trimmer safe")] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(CounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { lock (this) 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 d8bf7dcad1cc3..0e59ba8e6b256 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 @@ -1290,7 +1290,7 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel // So we need to prevent this from getting written directly to the Listeners. if (this.GetType() != typeof(NativeRuntimeEventSource)) #endif // MONO && !TARGET_BROWSER - WriteToAllListeners(eventId, pActivityId, relatedActivityId, eventDataCount, data); + WriteToAllListeners(eventId, pActivityId, relatedActivityId, eventDataCount, data); } } catch (Exception ex) @@ -1311,6 +1311,10 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel /// 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. /// +#if !ES_BUILD_STANDALONE + [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + + "Trimmer will not safely handle this case")] +#endif protected unsafe void WriteEvent(int eventId, params object?[] args) { WriteEventVarargs(eventId, null, args); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs index 4b4d08ec738bf..bc69942549f7a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs @@ -9,6 +9,7 @@ #if ES_BUILD_STANDALONE namespace Microsoft.Diagnostics.Tracing #else +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; namespace System.Diagnostics.Tracing @@ -56,6 +57,9 @@ public void Increment(double increment = 1) public override string ToString() => $"IncrementingEventCounter '{Name}' Increment {_increment}"; + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "IncrementingCounterPayload type has been trimmer safe")] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(IncrementingCounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { lock (this) // Lock the counter diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs index d18e5ad6f93c3..51abf7bac4778 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs @@ -8,6 +8,7 @@ #if ES_BUILD_STANDALONE namespace Microsoft.Diagnostics.Tracing #else +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; namespace System.Diagnostics.Tracing @@ -69,6 +70,9 @@ internal void UpdateMetric() } } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "IncrementingCounterPayload type has been trimmer safe")] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(IncrementingCounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { UpdateMetric(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs index d2b88669b21ac..3423916141afd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs @@ -8,6 +8,7 @@ #if ES_BUILD_STANDALONE namespace Microsoft.Diagnostics.Tracing #else +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; namespace System.Diagnostics.Tracing @@ -46,6 +47,9 @@ public PollingCounter(string name, EventSource eventSource, Func metricP private readonly Func _metricProvider; private double _lastVal; + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "CounterPayload type has been trimmer safe")] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(CounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { lock (this) 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 4087165e75b45..84817d2227a3e 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 @@ -17,6 +17,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Text; @@ -151,6 +152,10 @@ public unsafe void Write(string? eventName, EventSourceOptions options) /// public instance properties of data will be written recursively to /// create the fields of the event. /// +#if !ES_BUILD_STANDALONE + [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + + "Trimmer will not safely handle this case")] +#endif public unsafe void Write( string? eventName, T data) @@ -187,6 +192,10 @@ public unsafe void Write( /// public instance properties of data will be written recursively to /// create the fields of the event. /// +#if !ES_BUILD_STANDALONE + [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + + "Trimmer will not safely handle this case")] +#endif public unsafe void Write( string? eventName, EventSourceOptions options, @@ -225,6 +234,10 @@ public unsafe void Write( /// public instance properties of data will be written recursively to /// create the fields of the event. /// +#if !ES_BUILD_STANDALONE + [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + + "Trimmer will not safely handle this case")] +#endif public unsafe void Write( string? eventName, ref EventSourceOptions options, @@ -270,6 +283,10 @@ public unsafe void Write( /// public instance properties of data will be written recursively to /// create the fields of the event. /// +#if !ES_BUILD_STANDALONE + [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + + "Trimmer will not safely handle this case")] +#endif public unsafe void Write( string? eventName, ref EventSourceOptions options, diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs index 0324f31563bba..9c6af33a46434 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs @@ -5,6 +5,7 @@ using System; #endif using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Reflection; #if ES_BUILD_STANDALONE @@ -25,6 +26,10 @@ internal sealed class TypeAnalysis internal readonly EventOpcode opcode = (EventOpcode)(-1); internal readonly EventTags tags; +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", + Justification = "Trimmer does not support type recursion but is adding guards elsewhere")] +#endif public TypeAnalysis( Type dataType, EventDataAttribute? eventAttrib, 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 4d608bdbfcf5f..8f9d5569d90ac 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 @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using System.Diagnostics.Tracing; +using System.Diagnostics.CodeAnalysis; using Internal.Runtime.CompilerServices; namespace System.Threading.Tasks @@ -514,6 +515,8 @@ 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.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs index b61b1e52590ce..3cce48e100196 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs @@ -105,6 +105,8 @@ 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) { @@ -160,6 +162,8 @@ 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.Threading.Tasks.Dataflow/src/System.Threading.Tasks.Dataflow.csproj b/src/libraries/System.Threading.Tasks.Dataflow/src/System.Threading.Tasks.Dataflow.csproj index 7b324e8ca49c0..85534efa20842 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/System.Threading.Tasks.Dataflow.csproj +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/System.Threading.Tasks.Dataflow.csproj @@ -61,6 +61,9 @@ + + + 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 a22fee7dfad07..b1bb0e446ff95 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -838,6 +839,8 @@ 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 b6235135b32f7cfbd7386838c0f6d1e1e9c8cf9a Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 26 Feb 2021 11:33:56 -0800 Subject: [PATCH 04/24] Incorporating FB --- .../ref/System.Diagnostics.Tracing.cs | 10 +++++----- .../src/System/Diagnostics/Tracing/EventCounter.cs | 2 +- .../src/System/Diagnostics/Tracing/EventSource.cs | 4 ++-- .../Diagnostics/Tracing/IncrementingEventCounter.cs | 2 +- .../Tracing/IncrementingPollingCounter.cs | 2 +- .../System/Diagnostics/Tracing/PollingCounter.cs | 2 +- .../Tracing/TraceLogging/TraceLoggingEventSource.cs | 13 +++++-------- .../src/System/Threading/Tasks/TplEventSource.cs | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-) 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 07da9b336ef29..bcdca1b427b7d 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -190,7 +190,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) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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) { } protected void WriteEvent(int eventId, string? arg1, int arg2) { } @@ -203,13 +203,13 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, System.Dia protected void WriteEventWithRelatedActivityId(int eventId, System.Guid relatedActivityId, params object?[] args) { } [System.CLSCompliantAttribute(false)] protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Guid* relatedActivityId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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(string? eventName, System.Diagnostics.Tracing.EventSourceOptions options, T data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref System.Guid activityId, ref System.Guid relatedActivityId, ref T data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref T data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. Trimmer will not safely handle this case")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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(string? eventName, T data) { } [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/EventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs index ce25ed2702389..4bdd5a698c06a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs @@ -96,7 +96,7 @@ internal void OnMetricWritten(double value) } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "CounterPayload type has been trimmer safe")] + Justification = "The DynamicDependency will preserve the properties of CounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(CounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { 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 0e59ba8e6b256..6e4ce6b529e65 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 @@ -1312,8 +1312,8 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE - [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + - "Trimmer will not safely handle this case")] + [RequiresUnreferencedCode("EventSource WriteEvent 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")] #endif protected unsafe void WriteEvent(int eventId, params object?[] args) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs index bc69942549f7a..3e8b6c1a6a138 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs @@ -58,7 +58,7 @@ public void Increment(double increment = 1) public override string ToString() => $"IncrementingEventCounter '{Name}' Increment {_increment}"; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "IncrementingCounterPayload type has been trimmer safe")] + Justification = "The DynamicDependency will preserve the properties of IncrementingCounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(IncrementingCounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs index 51abf7bac4778..36e58597682e7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs @@ -71,7 +71,7 @@ internal void UpdateMetric() } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "IncrementingCounterPayload type has been trimmer safe")] + Justification = "The DynamicDependency will preserve the properties of IncrementingCounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(IncrementingCounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs index 3423916141afd..b2ead83b13f4c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs @@ -48,7 +48,7 @@ public PollingCounter(string name, EventSource eventSource, Func metricP private double _lastVal; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "CounterPayload type has been trimmer safe")] + Justification = "The DynamicDependency will preserve the properties of CounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(CounterPayload))] internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { 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 84817d2227a3e..e9e4dea0e5445 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 @@ -37,6 +37,7 @@ public partial class EventSource private byte[] ProviderMetadata => m_providerMetadata ?? Array.Empty(); #else private protected virtual ReadOnlySpan ProviderMetadata => m_providerMetadata; + private const string EventSourceRequiresUnreferenceMessage = "EventSource Write 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"; #endif #endif @@ -153,8 +154,7 @@ public unsafe void Write(string? eventName, EventSourceOptions options) /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + - "Trimmer will not safely handle this case")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif public unsafe void Write( string? eventName, @@ -193,8 +193,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + - "Trimmer will not safely handle this case")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif public unsafe void Write( string? eventName, @@ -235,8 +234,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + - "Trimmer will not safely handle this case")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif public unsafe void Write( string? eventName, @@ -284,8 +282,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [RequiresUnreferencedCode("EventSource Write Event is not safe due to type description data. " + - "Trimmer will not safely handle this case")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif public unsafe void Write( string? eventName, 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 8f9d5569d90ac..3f3ed60a35a6f 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 @@ -516,7 +516,7 @@ public void RunningContinuationList(int TaskID, int Index, long Object) 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")] + Justification = "Guid parameter is safe with WriteEvent")] [Event(25, Keywords = Keywords.DebugActivityId)] public void SetActivityId(Guid NewId) { From 045e38ddfafe5e5a91552c5f976883ea7774b434 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 1 Mar 2021 10:13:40 -0800 Subject: [PATCH 05/24] Update src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs Co-authored-by: Eric Erhardt --- .../src/System/Diagnostics/DiagnosticSourceEventSource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index 741e2ec484a96..cb5ab204f9a74 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -328,7 +328,7 @@ private void NewDiagnosticListener(string SourceName) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] #if NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT - [Event(11, Keywords = Keywords.Events)] + [Event(11, Keywords = Keywords.Events)] #else [Event(11, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)] #endif From a9dda65185dd917cbaa5287e456abfdd075cef24 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 1 Mar 2021 10:13:55 -0800 Subject: [PATCH 06/24] Update src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs Co-authored-by: Eric Erhardt --- .../src/System/Diagnostics/DiagnosticSourceEventSource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index cb5ab204f9a74..2fe664ff59871 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -344,7 +344,7 @@ private void ActivityStart(string SourceName, string ActivityName, IEnumerable Date: Mon, 1 Mar 2021 10:14:05 -0800 Subject: [PATCH 07/24] Update src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Co-authored-by: Eric Erhardt --- .../src/System/Diagnostics/Tracing/EventSource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6e4ce6b529e65..d1308fdacdd76 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 @@ -1290,7 +1290,7 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel // So we need to prevent this from getting written directly to the Listeners. if (this.GetType() != typeof(NativeRuntimeEventSource)) #endif // MONO && !TARGET_BROWSER - WriteToAllListeners(eventId, pActivityId, relatedActivityId, eventDataCount, data); + WriteToAllListeners(eventId, pActivityId, relatedActivityId, eventDataCount, data); } } catch (Exception ex) From ea460c35698222b590355e4721fb88049c3d84a8 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 1 Mar 2021 10:52:52 -0800 Subject: [PATCH 08/24] Fix DynamicDependency as per PR feedback --- .../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 e9e4dea0e5445..16795e4b32ea3 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 @@ -195,7 +195,7 @@ public unsafe void Write( #if !ES_BUILD_STANDALONE [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif - public unsafe void Write( + public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( string? eventName, EventSourceOptions options, T data) From 3e56d852c01f1b91f7138eade8710ce1cbb521cb Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 1 Mar 2021 11:47:27 -0800 Subject: [PATCH 09/24] an earlier change got reverted --- .../Diagnostics/DiagnosticSourceEventSource.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index 2fe664ff59871..5c90e7b827cfc 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -223,8 +223,10 @@ public void Message(string? Message) /// /// Events from DiagnosticSource can be forwarded to EventSource using this event. /// +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif [Event(2, Keywords = Keywords.Events)] private void Event(string SourceName, string EventName, IEnumerable>? Arguments) { @@ -245,8 +247,10 @@ private void EventJson(string SourceName, string EventName, string ArgmentsJson) /// /// Used to mark the beginning of an activity /// +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif [Event(4, Keywords = Keywords.Events)] private void Activity1Start(string SourceName, string EventName, IEnumerable> Arguments) { @@ -256,8 +260,10 @@ private void Activity1Start(string SourceName, string EventName, IEnumerable /// Used to mark the end of an activity /// +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif [Event(5, Keywords = Keywords.Events)] private void Activity1Stop(string SourceName, string EventName, IEnumerable> Arguments) { @@ -267,8 +273,10 @@ private void Activity1Stop(string SourceName, string EventName, IEnumerable /// Used to mark the beginning of an activity /// +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif [Event(6, Keywords = Keywords.Events)] private void Activity2Start(string SourceName, string EventName, IEnumerable> Arguments) { @@ -278,8 +286,10 @@ private void Activity2Start(string SourceName, string EventName, IEnumerable /// Used to mark the end of an activity that can be recursive. /// +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif [Event(7, Keywords = Keywords.Events)] private void Activity2Stop(string SourceName, string EventName, IEnumerable> Arguments) { @@ -289,8 +299,10 @@ private void Activity2Stop(string SourceName, string EventName, IEnumerable /// Used to mark the beginning of an activity /// +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif [Event(8, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)] private void RecursiveActivity1Start(string SourceName, string EventName, IEnumerable> Arguments) { @@ -300,8 +312,10 @@ private void RecursiveActivity1Start(string SourceName, string EventName, IEnume /// /// Used to mark the end of an activity that can be recursive. /// +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif [Event(9, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)] private void RecursiveActivity1Stop(string SourceName, string EventName, IEnumerable> Arguments) { @@ -325,8 +339,10 @@ private void NewDiagnosticListener(string SourceName) /// The ActivitySource name /// The Activity name /// Name and value pairs of the Activity properties +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif #if NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT [Event(11, Keywords = Keywords.Events)] #else @@ -341,8 +357,10 @@ private void ActivityStart(string SourceName, string ActivityName, IEnumerableThe ActivitySource name /// The Activity name /// Name and value pairs of the Activity properties +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")] +#endif #if NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT [Event(12, Keywords = Keywords.Events)] #else From aa2a21d10f201923a5e8e8e7f9bd78ac55dfc364 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 1 Mar 2021 13:03:30 -0800 Subject: [PATCH 10/24] fixed proj file netcore app condition check --- .../src/System.Diagnostics.DiagnosticSource.csproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj index 71a05264bc3d7..d5a7d0ac9ff5a 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj @@ -31,6 +31,7 @@ + @@ -84,9 +85,6 @@ - - - From 3d61a4494a42b1f48254e6592660d8387a382354 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 1 Mar 2021 13:45:12 -0800 Subject: [PATCH 11/24] fixed NETCORE_ENGINEERING_TELEMETRY build failures --- .../src/System/Diagnostics/Tracing/EventCounter.cs | 2 ++ .../src/System/Diagnostics/Tracing/IncrementingEventCounter.cs | 2 ++ .../System/Diagnostics/Tracing/IncrementingPollingCounter.cs | 2 ++ .../src/System/Diagnostics/Tracing/PollingCounter.cs | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs index 4bdd5a698c06a..34a6d02101c99 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs @@ -95,9 +95,11 @@ internal void OnMetricWritten(double value) _count++; } +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The DynamicDependency will preserve the properties of CounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(CounterPayload))] +#endif internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { lock (this) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs index 3e8b6c1a6a138..633ab218a5e16 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs @@ -57,9 +57,11 @@ public void Increment(double increment = 1) public override string ToString() => $"IncrementingEventCounter '{Name}' Increment {_increment}"; +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The DynamicDependency will preserve the properties of IncrementingCounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(IncrementingCounterPayload))] +#endif internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { lock (this) // Lock the counter diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs index 36e58597682e7..1097c38f80fe9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs @@ -70,9 +70,11 @@ internal void UpdateMetric() } } +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The DynamicDependency will preserve the properties of IncrementingCounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(IncrementingCounterPayload))] +#endif internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { UpdateMetric(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs index b2ead83b13f4c..5b3063f934c31 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs @@ -47,9 +47,11 @@ public PollingCounter(string name, EventSource eventSource, Func metricP private readonly Func _metricProvider; private double _lastVal; +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The DynamicDependency will preserve the properties of CounterPayload")] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(CounterPayload))] +#endif internal override void WritePayload(float intervalSec, int pollingIntervalMillisec) { lock (this) From 5775e1a7c2856e96d8ccd2d46349831783e16e64 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 1 Mar 2021 14:20:48 -0800 Subject: [PATCH 12/24] fixeing another NETCORE_ENGINEERING_TELEMETRY build failures --- .../Tracing/TraceLogging/TraceLoggingEventSource.cs | 4 +++- 1 file changed, 3 insertions(+), 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 16795e4b32ea3..b00a146e3c502 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 @@ -194,8 +194,10 @@ public unsafe void Write( /// #if !ES_BUILD_STANDALONE [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] -#endif public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( +#else + public unsafe void Write( +#endif string? eventName, EventSourceOptions options, T data) From f1d3a1b09fab2c0ca8302bb4084b1524b150e17f Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 2 Mar 2021 07:02:45 -0800 Subject: [PATCH 13/24] Adding RequiresUnreferencedCode to TypeAnalysis ctor instead of suppressing the warning to get FB, not fully fixed --- .../src/System/Diagnostics/Tracing/EventSource.cs | 5 +++++ .../Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs | 1 + .../Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs | 1 + .../src/System/Diagnostics/Tracing/TraceLogging/Statics.cs | 1 + .../Tracing/TraceLogging/TraceLoggingEventTypes.cs | 4 ++++ .../Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs | 1 + .../System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs | 3 +-- 7 files changed, 14 insertions(+), 2 deletions(-) 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 d1308fdacdd76..db458f715e3d1 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 @@ -1184,6 +1184,7 @@ internal unsafe void SetMetadata(byte* pointer, int size, int reserved) /// } /// /// + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] [CLSCompliant(false)] protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSource.EventData* data) { @@ -1215,6 +1216,7 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSourc /// } /// /// + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] [CLSCompliant(false)] protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* relatedActivityId, int eventDataCount, EventSource.EventData* data) { @@ -1765,6 +1767,7 @@ private static Guid GenerateGuidFromName(string name) return dispatcher; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object?[] args) { if (IsEnabled()) @@ -1890,6 +1893,7 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object } } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 unsafe object?[] SerializeEventArgs(int eventId, object?[] args) { Debug.Assert(m_eventData != null); @@ -2044,6 +2048,7 @@ private unsafe void DispatchToAllListeners(int eventId, EventWrittenEventArgs ev // ETW and EventPipe providers. It is not a general purpose API, it will // log the message with Level=LogAlways and Keywords=All to make sure whoever // is listening gets the message. + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 unsafe void WriteEventString(string msgString) { #if FEATURE_MANAGED_ETW || FEATURE_PERFTRACING diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs index 4218aaec8f50d..021e1ee447c48 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs @@ -27,6 +27,7 @@ internal static class SimpleEventTypes public static TraceLoggingEventTypes Instance => instance ?? InitInstance(); + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 static TraceLoggingEventTypes InitInstance() { var info = TraceLoggingTypeInfo.GetInstance(typeof(T), null); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs index 76b94d9cbe68f..4cfd9b929ae08 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs @@ -271,6 +271,7 @@ internal sealed class NullableTypeInfo : TraceLoggingTypeInfo { private readonly TraceLoggingTypeInfo valueInfo; + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 NullableTypeInfo(Type type, List recursionCheck) : base(type) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs index b7ad6be87d6bf..1045dd294e102 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs @@ -381,6 +381,7 @@ public static bool IsGenericMatch(Type type, object? openType) return type.IsGenericType && type.GetGenericTypeDefinition() == (Type?)openType; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 static TraceLoggingTypeInfo CreateDefaultTypeInfo( Type dataType, List recursionCheck) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs index feb96bf642222..96b25e24d7a09 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs @@ -48,6 +48,7 @@ public class TraceLoggingEventTypes /// /// The types of the fields in the event. This value must not be null. /// + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] internal TraceLoggingEventTypes( string name, EventTags tags, @@ -82,6 +83,7 @@ internal TraceLoggingEventTypes( { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] internal TraceLoggingEventTypes( string name, EventTags tags, @@ -180,6 +182,7 @@ internal NameInfo GetNameInfo(string name, EventTags tags) => this.nameInfos.TryGet(new KeyValuePair(name, tags)) ?? this.nameInfos.GetOrAdd(new NameInfo(name, tags, this.typeMetadata.Length)); + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 static TraceLoggingTypeInfo[] MakeArray(System.Reflection.ParameterInfo[] paramInfos) { if (paramInfos == null) @@ -197,6 +200,7 @@ private static TraceLoggingTypeInfo[] MakeArray(System.Reflection.ParameterInfo[ return result; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 static TraceLoggingTypeInfo[] MakeArray(Type[] types) { if (types == null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs index 6f57f667dcc2c..ebd23e9d9060b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs @@ -153,6 +153,7 @@ public abstract void WriteMetadata( [ThreadStatic] // per-thread cache to avoid synchronization private static Dictionary? threadCache; + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 static TraceLoggingTypeInfo GetInstance(Type type, List? recursionCheck) { Dictionary cache = threadCache ??= new Dictionary(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs index 9c6af33a46434..6fdbe7be20258 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs @@ -27,8 +27,7 @@ internal sealed class TypeAnalysis internal readonly EventTags tags; #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", - Justification = "Trimmer does not support type recursion but is adding guards elsewhere")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] #endif public TypeAnalysis( Type dataType, From 589ee3fe70b83d15de8ac33a7ca0dc8189579438 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 2 Mar 2021 17:04:58 -0800 Subject: [PATCH 14/24] PR FB and suppressing warnings for safe calls --- .../ref/System.Diagnostics.Tracing.cs | 2 ++ .../src/System/Net/Http/HttpTelemetry.cs | 12 ++++++++++++ .../src/ILLink/ILLink.Suppressions.Shared.xml | 6 ------ .../System/Diagnostics/Tracing/EventSource.cs | 19 +++++++++++++++++-- .../Tracing/TraceLogging/SimpleEventTypes.cs | 6 +++++- 5 files changed, 36 insertions(+), 9 deletions(-) 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 bcdca1b427b7d..659271e1886a3 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -198,9 +198,11 @@ protected void WriteEvent(int eventId, string? arg1, int arg2, int arg3) { } protected void WriteEvent(int eventId, string? arg1, long arg2) { } protected void WriteEvent(int eventId, string? arg1, string? arg2) { } protected void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3) { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] [System.CLSCompliantAttribute(false)] protected unsafe void WriteEventCore(int eventId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { } protected void WriteEventWithRelatedActivityId(int eventId, System.Guid relatedActivityId, params object?[] args) { } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] [System.CLSCompliantAttribute(false)] protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Guid* relatedActivityId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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")] diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs index 385d959770732..a008637271e1a 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs @@ -158,6 +158,10 @@ public void Http20ConnectionClosed() ConnectionClosed(versionMajor: 2, versionMinor: 0); } +#if !ES_BUILD_STANDALONE + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Parameters to this method are primitive and are trimmer safe")] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3, string? arg4, byte arg5, byte arg6, HttpVersionPolicy arg7) { @@ -215,6 +219,10 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3 } } +#if !ES_BUILD_STANDALONE + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Parameters to this method are primitive and are trimmer safe")] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, double arg1, byte arg2, byte arg3) { @@ -243,6 +251,10 @@ private unsafe void WriteEvent(int eventId, double arg1, byte arg2, byte arg3) } } +#if !ES_BUILD_STANDALONE + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Parameters to this method are primitive and are trimmer safe")] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, byte arg1, byte arg2) { 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 50960f8c7e113..0dc3b55fc8603 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 - IL2070 - member - M:System.Diagnostics.Tracing.TypeAnalysis.#ctor(System.Type,System.Diagnostics.Tracing.EventDataAttribute,System.Collections.Generic.List{System.Type}) - ILLink IL2072 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 db458f715e3d1..1e07ccf600a6d 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 @@ -1184,7 +1184,9 @@ internal unsafe void SetMetadata(byte* pointer, int size, int reserved) /// } /// /// +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif [CLSCompliant(false)] protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSource.EventData* data) { @@ -1216,7 +1218,9 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSourc /// } /// /// +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif [CLSCompliant(false)] protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* relatedActivityId, int eventDataCount, EventSource.EventData* data) { @@ -1767,7 +1771,9 @@ private static Guid GenerateGuidFromName(string name) return dispatcher; } +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object?[] args) { if (IsEnabled()) @@ -1893,7 +1899,9 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object } } +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif private unsafe object?[] SerializeEventArgs(int eventId, object?[] args) { Debug.Assert(m_eventData != null); @@ -2048,7 +2056,6 @@ private unsafe void DispatchToAllListeners(int eventId, EventWrittenEventArgs ev // ETW and EventPipe providers. It is not a general purpose API, it will // log the message with Level=LogAlways and Keywords=All to make sure whoever // is listening gets the message. - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 unsafe void WriteEventString(string msgString) { #if FEATURE_MANAGED_ETW || FEATURE_PERFTRACING @@ -2074,7 +2081,15 @@ private unsafe void WriteEventString(string msgString) Keywords = (EventKeywords)unchecked(keywords), Level = level }; - var tlet = new TraceLoggingEventTypes(EventName, EventTags.None, new Type[] { typeof(string) }); + +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "The call to TraceLoggingEventTypes with the below parameter values are trim safe")] +#endif + static TraceLoggingEventTypes GetTrimSafeTraceLoggingEventTypes() => + new TraceLoggingEventTypes(EventName, EventTags.None, new Type[] { typeof(string) }); + + var tlet = GetTrimSafeTraceLoggingEventTypes(); WriteMultiMergeInner(EventName, ref opt, tlet, null, null, msgString); } else diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs index 021e1ee447c48..db4ea1db0e808 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs @@ -25,7 +25,11 @@ internal static class SimpleEventTypes { private static TraceLoggingEventTypes? instance; - public static TraceLoggingEventTypes Instance => instance ?? InitInstance(); + public static TraceLoggingEventTypes Instance + { + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + get { return instance ??= InitInstance(); } + } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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 static TraceLoggingEventTypes InitInstance() From bb4a18daa9dfa57b8ef16c6f3efda2d1e9ec897d Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 3 Mar 2021 10:52:37 -0800 Subject: [PATCH 15/24] propagated the warning all the way up --- .../Net/Logging/NetEventSource.Common.cs | 37 +++++++++ .../ref/System.Diagnostics.Tracing.cs | 15 ++-- .../src/System.Net.Http.WinHttpHandler.csproj | 3 + .../System/Net/Http/NetEventSource.Http.cs | 5 ++ .../src/System/Net/NameResolutionTelemetry.cs | 5 ++ .../Net/Security/NetSecurityTelemetry.cs | 16 ++++ .../System/Buffers/ArrayPoolEventSource.cs | 12 +++ .../System/Diagnostics/Tracing/EventSource.cs | 82 +++++++++++++++++-- .../Tracing/FrameworkEventSource.cs | 12 +++ .../TraceLogging/TraceLoggingEventSource.cs | 23 +++++- .../System/Threading/Tasks/TplEventSource.cs | 27 ++++++ .../Threading/Tasks/ParallelETWProvider.cs | 16 ++++ .../System/Threading/CDSsyncETWBCLProvider.cs | 5 ++ 13 files changed, 241 insertions(+), 17 deletions(-) diff --git a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs index ebad4b73e03a8..9b6f05819de5f 100644 --- a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs +++ b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs @@ -10,6 +10,7 @@ using System.Collections; using System.Diagnostics; using System.Diagnostics.Tracing; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; #if NET46 @@ -43,6 +44,10 @@ namespace System.Net #endif internal sealed partial class NetEventSource : EventSource { +#if !ES_BUILD_STANDALONE + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; +#endif + /// The single event source instance to use for all logging. public static readonly NetEventSource Log = new NetEventSource(); @@ -373,6 +378,10 @@ private static string Format(FormattableString s) #region Custom WriteEvent overloads +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, string? arg4) { @@ -417,6 +426,10 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, byte[]? arg3) { @@ -460,6 +473,10 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, byte[]? } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3, int arg4) { @@ -498,6 +515,10 @@ private unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3, in } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, int arg2, string? arg3) { @@ -533,6 +554,10 @@ private unsafe void WriteEvent(int eventId, string? arg1, int arg2, string? arg3 } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3) { @@ -568,6 +593,10 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3 } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, int arg4) { @@ -610,6 +639,10 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8) { @@ -668,6 +701,10 @@ private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3, int arg4, int arg5) { 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 659271e1886a3..9cec03aa32774 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -190,7 +190,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) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + [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) { } protected void WriteEvent(int eventId, string? arg1, int arg2) { } @@ -198,20 +198,21 @@ protected void WriteEvent(int eventId, string? arg1, int arg2, int arg3) { } protected void WriteEvent(int eventId, string? arg1, long arg2) { } protected void WriteEvent(int eventId, string? arg1, string? arg2) { } protected void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + [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")] [System.CLSCompliantAttribute(false)] protected unsafe void WriteEventCore(int eventId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { } + [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 WriteEventWithRelatedActivityId(int eventId, System.Guid relatedActivityId, params object?[] args) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + [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")] [System.CLSCompliantAttribute(false)] protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Guid* relatedActivityId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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")] + [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(string? eventName, System.Diagnostics.Tracing.EventSourceOptions options, T data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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")] + [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(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref System.Guid activityId, ref System.Guid relatedActivityId, ref T data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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")] + [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(string? eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref T data) { } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource Write 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")] + [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(string? eventName, T data) { } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] protected internal partial struct EventData diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj index 8e62c79985b8c..91be83654d3be 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj @@ -11,6 +11,9 @@ $(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.6.1\1.0.1\lib\net461\;$(AssemblySearchPaths) + + + diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs b/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs index 5ba0eed91c17d..d1de2d9735399 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; namespace System.Net @@ -73,6 +74,10 @@ public static void AuthenticationError(Uri? uri, string message) public void AuthenticationError(string? uri, string message) => WriteEvent(AuthenticationErrorId, uri, message); +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = "Parameters to this method are primitive and are trimmer safe")] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3, string? arg4, string? arg5) { diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs index 81cc5f62597c3..057fcdd48f34d 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Runtime.InteropServices; using System.Threading; @@ -132,6 +133,10 @@ private static Span FormatIPAddressNullTerminated(IPAddress address, Span< // WriteEvent overloads taking Span are imitating string arguments // Span arguments are expected to be null-terminated +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = "Parameters to this method are primitive and are trimmer safe")] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, Span arg1) { diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs b/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs index 0c393405bfc4c..eaeb6026dd86e 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Diagnostics.Tracing; +using System.Diagnostics.CodeAnalysis; using System.Security.Authentication; using System.Threading; using Microsoft.Extensions.Internal; @@ -12,6 +13,9 @@ namespace System.Net.Security [EventSource(Name = "System.Net.Security")] internal sealed class NetSecurityTelemetry : EventSource { +#if !ES_BUILD_STANDALONE + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; +#endif public static readonly NetSecurityTelemetry Log = new NetSecurityTelemetry(); private IncrementingPollingCounter? _tlsHandshakeRateCounter; @@ -240,6 +244,10 @@ public void ConnectionClosed(SslProtocols protocol) } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, bool arg1, string? arg2) { @@ -268,6 +276,10 @@ private unsafe void WriteEvent(int eventId, bool arg1, string? arg2) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, SslProtocols arg1) { @@ -283,6 +295,10 @@ private unsafe void WriteEvent(int eventId, SslProtocols arg1) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, bool arg1, double arg2, string? arg3) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs index 2f6ac1842393d..b76c04b890e6c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.Tracing; +using System.Diagnostics.CodeAnalysis; namespace System.Buffers { @@ -9,6 +10,9 @@ namespace System.Buffers [EventSourceAutoGenerate] internal sealed partial class ArrayPoolEventSource : EventSource { +#if !ES_BUILD_STANDALONE + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; +#endif internal static readonly ArrayPoolEventSource Log = new ArrayPoolEventSource(); /// The reason for a BufferAllocated event. @@ -34,6 +38,10 @@ private ArrayPoolEventSource(int _) { } /// of BufferAllocated events being less than or equal to those numbers (ideally significantly /// less than). /// +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(1, Level = EventLevel.Verbose)] internal unsafe void BufferRented(int bufferId, int bufferSize, int poolId, int bucketId) { @@ -58,6 +66,10 @@ internal unsafe void BufferRented(int bufferId, int bufferSize, int poolId, int /// of BufferAllocated events is significantly smaller than the number of BufferRented and /// BufferReturned events. /// +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(2, Level = EventLevel.Informational)] internal unsafe void BufferAllocated(int bufferId, int bufferSize, int poolId, int bucketId, BufferAllocatedReason reason) { 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 1e07ccf600a6d..9e1d568f83279 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 @@ -765,12 +765,20 @@ protected virtual void OnEventCommand(EventCommandEventArgs command) { } #pragma warning disable 1591 // optimized for common signatures (no args) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId) { WriteEventCore(eventId, 0, null); } // optimized for common signatures (ints) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, int arg1) { if (IsEnabled()) @@ -783,6 +791,10 @@ protected unsafe void WriteEvent(int eventId, int arg1) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, int arg1, int arg2) { if (IsEnabled()) @@ -798,6 +810,10 @@ protected unsafe void WriteEvent(int eventId, int arg1, int arg2) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3) { if (IsEnabled()) @@ -817,6 +833,10 @@ protected unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3) } // optimized for common signatures (longs) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, long arg1) { if (IsEnabled()) @@ -829,6 +849,10 @@ protected unsafe void WriteEvent(int eventId, long arg1) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, long arg1, long arg2) { if (IsEnabled()) @@ -844,6 +868,10 @@ protected unsafe void WriteEvent(int eventId, long arg1, long arg2) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, long arg1, long arg2, long arg3) { if (IsEnabled()) @@ -863,6 +891,10 @@ protected unsafe void WriteEvent(int eventId, long arg1, long arg2, long arg3) } // optimized for common signatures (strings) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, string? arg1) { if (IsEnabled()) @@ -879,6 +911,10 @@ protected unsafe void WriteEvent(int eventId, string? arg1) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2) { if (IsEnabled()) @@ -900,6 +936,10 @@ protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3) { if (IsEnabled()) @@ -927,6 +967,10 @@ protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string } // optimized for common signatures (string and ints) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, string? arg1, int arg2) { if (IsEnabled()) @@ -946,6 +990,10 @@ protected unsafe void WriteEvent(int eventId, string? arg1, int arg2) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3) { if (IsEnabled()) @@ -969,6 +1017,10 @@ protected unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3) } // optimized for common signatures (string and longs) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, string? arg1, long arg2) { if (IsEnabled()) @@ -989,6 +1041,10 @@ protected unsafe void WriteEvent(int eventId, string? arg1, long arg2) } // optimized for common signatures (long and string) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, long arg1, string? arg2) { if (IsEnabled()) @@ -1009,6 +1065,10 @@ protected unsafe void WriteEvent(int eventId, long arg1, string? arg2) } // optimized for common signatures (int and string) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, int arg1, string? arg2) { if (IsEnabled()) @@ -1028,6 +1088,10 @@ protected unsafe void WriteEvent(int eventId, int arg1, string? arg2) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, byte[]? arg1) { if (IsEnabled()) @@ -1061,6 +1125,10 @@ protected unsafe void WriteEvent(int eventId, byte[]? arg1) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif protected unsafe void WriteEvent(int eventId, long arg1, byte[]? arg2) { if (IsEnabled()) @@ -1185,7 +1253,7 @@ internal unsafe void SetMetadata(byte* pointer, int size, int reserved) /// /// #if !ES_BUILD_STANDALONE - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif [CLSCompliant(false)] protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSource.EventData* data) @@ -1219,7 +1287,7 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSourc /// /// #if !ES_BUILD_STANDALONE - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif [CLSCompliant(false)] protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* relatedActivityId, int eventDataCount, EventSource.EventData* data) @@ -1318,8 +1386,7 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE - [RequiresUnreferencedCode("EventSource WriteEvent 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")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif protected unsafe void WriteEvent(int eventId, params object?[] args) { @@ -1334,6 +1401,9 @@ protected unsafe void WriteEvent(int eventId, params object?[] args) /// 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. /// +#if !ES_BUILD_STANDALONE + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] +#endif protected unsafe void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, params object?[] args) { WriteEventVarargs(eventId, &relatedActivityId, args); @@ -1772,7 +1842,7 @@ private static Guid GenerateGuidFromName(string name) } #if !ES_BUILD_STANDALONE - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object?[] args) { @@ -1900,7 +1970,7 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object } #if !ES_BUILD_STANDALONE - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] + [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif private unsafe object?[] SerializeEventArgs(int eventId, object?[] args) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs index d1e3cfe154e27..700955e8cad4b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using Internal.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; namespace System.Diagnostics.Tracing { @@ -10,6 +11,9 @@ namespace System.Diagnostics.Tracing [EventSourceAutoGenerate] internal sealed partial class FrameworkEventSource : EventSource { +#if !ES_BUILD_STANDALONE + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; +#endif public static readonly FrameworkEventSource Log = new FrameworkEventSource(); // Keyword definitions. These represent logical groups of events that can be turned on and off independently @@ -34,6 +38,10 @@ public static class Keywords private FrameworkEventSource(int _) { } // optimized for common signatures (used by the ThreadTransferSend/Receive events) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, long arg1, int arg2, string? arg3, bool arg4, int arg5, int arg6) { @@ -67,6 +75,10 @@ private unsafe void WriteEvent(int eventId, long arg1, int arg2, string? arg3, b } // optimized for common signatures (used by the ThreadTransferSend/Receive events) +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteEvent(int eventId, long arg1, int arg2, string? arg3) { 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 b00a146e3c502..00dd8277fca5b 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 @@ -37,7 +37,8 @@ public partial class EventSource private byte[] ProviderMetadata => m_providerMetadata ?? Array.Empty(); #else private protected virtual ReadOnlySpan ProviderMetadata => m_providerMetadata; - private const string EventSourceRequiresUnreferenceMessage = "EventSource Write 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. This can be suppressed if the object is a primitive type"; + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; #endif #endif @@ -104,6 +105,10 @@ public EventSource( /// (Native API: EventWriteTransfer) /// /// The name of the event. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif public unsafe void Write(string? eventName) { if (!this.IsEnabled()) @@ -124,6 +129,10 @@ public unsafe void Write(string? eventName) /// Options for the event, such as the level, keywords, and opcode. Unset /// options will be set to default values. /// +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif public unsafe void Write(string? eventName, EventSourceOptions options) { if (!this.IsEnabled()) @@ -155,8 +164,10 @@ public unsafe void Write(string? eventName, EventSourceOptions options) /// #if !ES_BUILD_STANDALONE [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] -#endif + public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( +#else public unsafe void Write( +#endif string? eventName, T data) { @@ -237,8 +248,10 @@ public unsafe void Write( /// #if !ES_BUILD_STANDALONE [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] -#endif + public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( +#else public unsafe void Write( +#endif string? eventName, ref EventSourceOptions options, ref T data) @@ -285,8 +298,10 @@ public unsafe void Write( /// #if !ES_BUILD_STANDALONE [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] -#endif + public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( +#else public unsafe void Write( +#endif string? eventName, ref EventSourceOptions options, ref Guid activityId, 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 3f3ed60a35a6f..eea410711a367 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 @@ -22,6 +22,9 @@ namespace System.Threading.Tasks [EventSourceAutoGenerate] internal sealed partial class TplEventSource : EventSource { +#if !ES_BUILD_STANDALONE + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; +#endif /// Used to determine if tasks should generate Activity IDs for themselves internal bool TasksSetActivityIds; // This keyword is set internal bool Debug; @@ -190,6 +193,10 @@ public enum TaskWaitBehavior : int /// The task ID /// The options used to create the task. /// The ID for the current AppDomain. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(TASKSCHEDULED_ID, Task = Tasks.TaskScheduled, Version = 1, Opcode = EventOpcode.Send, Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)] public void TaskScheduled( @@ -258,6 +265,10 @@ public void TaskStarted( /// The task ID. /// The task ID. /// Whether the task completed due to an error. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(TASKCOMPLETED_ID, Version = 1, Level = EventLevel.Informational, Keywords = Keywords.TaskStops)] public void TaskCompleted( @@ -300,6 +311,10 @@ public void TaskCompleted( /// If known, if 'TaskID' has a 'continueWith' task, mention give its ID here. /// 0 means unknown. This allows better visualization of the common sequential chaining case. /// +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(TASKWAITBEGIN_ID, Version = 3, Task = TplEventSource.Tasks.TaskWait, Opcode = EventOpcode.Send, Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)] public void TaskWaitBegin( @@ -389,6 +404,10 @@ public void TaskWaitContinuationStarted(int TaskID) /// The scheduler ID. /// The task ID. /// The ID of the continuation object. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(AWAITTASKCONTINUATIONSCHEDULED_ID, Task = Tasks.AwaitTaskContinuationScheduled, Opcode = EventOpcode.Send, Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)] public void AwaitTaskContinuationScheduled( @@ -420,6 +439,10 @@ public void AwaitTaskContinuationScheduled( } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(TRACEOPERATIONSTART_ID, Version = 1, Level = EventLevel.Informational, Keywords = Keywords.AsyncCausalityOperation)] public void TraceOperationBegin(int TaskID, string OperationName, long RelatedContext) @@ -472,6 +495,10 @@ public void TraceSynchronousWorkBegin(int TaskID, CausalitySynchronousWork Work) WriteEvent(TRACESYNCHRONOUSWORKSTART_ID, TaskID, (int)Work); // optimized overload for this exists } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(TRACESYNCHRONOUSWORKSTOP_ID, Version = 1, Level = EventLevel.Informational, Keywords = Keywords.AsyncCausalitySynchronousWork)] public void TraceSynchronousWorkEnd(CausalitySynchronousWork Work) diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs index 2770ba67993d8..aa5f6862da883 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Text; using System.Security; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; namespace System.Threading.Tasks @@ -19,6 +20,9 @@ namespace System.Threading.Tasks [EventSource(Name = "System.Threading.Tasks.Parallel.EventSource")] internal sealed class ParallelEtwProvider : EventSource { +#if !ES_BUILD_STANDALONE + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; +#endif /// /// Defines the singleton instance for the Task.Parallel ETW provider. /// @@ -97,6 +101,10 @@ public class Tasks /// The kind of fork/join operation. /// The lower bound of the loop. /// The upper bound of the loop. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(PARALLELLOOPBEGIN_ID, Level = EventLevel.Informational, Task = ParallelEtwProvider.Tasks.Loop, Opcode = EventOpcode.Start)] public void ParallelLoopBegin(int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER int ForkJoinContextID, ForkJoinOperationType OperationType, // PFX_FORKJOIN_COMMON_EVENT_HEADER @@ -157,6 +165,10 @@ public void ParallelLoopBegin(int OriginatingTaskSchedulerID, int OriginatingTas /// The task ID. /// The loop ID. /// the total number of iterations processed. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(PARALLELLOOPEND_ID, Level = EventLevel.Informational, Task = ParallelEtwProvider.Tasks.Loop, Opcode = EventOpcode.Stop)] public void ParallelLoopEnd(int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER int ForkJoinContextID, long TotalIterations) @@ -204,6 +216,10 @@ public void ParallelLoopEnd(int OriginatingTaskSchedulerID, int OriginatingTaskI /// The invoke ID. /// The kind of fork/join operation. /// The number of actions being invoked. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(PARALLELINVOKEBEGIN_ID, Level = EventLevel.Informational, Task = ParallelEtwProvider.Tasks.Invoke, Opcode = EventOpcode.Start)] public void ParallelInvokeBegin(int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER int ForkJoinContextID, ForkJoinOperationType OperationType, // PFX_FORKJOIN_COMMON_EVENT_HEADER diff --git a/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs b/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs index 0837744cfb987..149839f8a5038 100644 --- a/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs +++ b/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using System.Text; using System.Security; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; namespace System.Threading @@ -56,6 +57,10 @@ private CdsSyncEtwBCLProvider() { } // Barrier Events // +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = "Parameters to this method are primitive and are trimmer safe")] +#endif [Event(BARRIER_PHASEFINISHED_ID, Level = EventLevel.Verbose, Version = 1)] public void Barrier_PhaseFinished(bool currentSense, long phaseNum) { From 024c8d654c624b28aea4df69ce4bf8c8d1de4fed Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 3 Mar 2021 15:52:47 -0800 Subject: [PATCH 16/24] CI build break fix for one file --- ...veRuntimeEventSource.PortableThreadPool.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs index b15be430a9de5..dc0278d4f975a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs @@ -13,6 +13,9 @@ namespace System.Diagnostics.Tracing // To look at CoreCLR implementation of these events, refer to NativeRuntimeEventSource.PortableThreadPool.CoreCLR.cs. internal sealed partial class NativeRuntimeEventSource : EventSource { +#if !ES_BUILD_STANDALONE + private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; +#endif // This value does not seem to be used, leaving it as zero for now. It may be useful for a scenario that may involve // multiple instances of the runtime within the same process, but then it seems unlikely that both instances' thread // pools would be in moderate use. @@ -135,6 +138,10 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentSample( WriteEventCore(54, 2, data); } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(55, Level = EventLevel.Informational, Message = Messages.WorkerThreadAdjustmentAdjustment, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Adjustment, Version = 0, Keywords = Keywords.ThreadingKeyword)] public unsafe void ThreadPoolWorkerThreadAdjustmentAdjustment( double AverageThroughput, @@ -162,6 +169,10 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentAdjustment( WriteEventCore(55, 4, data); } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(56, Level = EventLevel.Verbose, Message = Messages.WorkerThreadAdjustmentStats, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Stats, Version = 0, Keywords = Keywords.ThreadingKeyword)] public unsafe void ThreadPoolWorkerThreadAdjustmentStats( double Duration, @@ -217,6 +228,10 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentStats( WriteEventCore(56, 11, data); } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(63, Level = EventLevel.Verbose, Message = Messages.IOEnqueue, Task = Tasks.ThreadPool, Opcode = Opcodes.IOEnqueue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)] private unsafe void ThreadPoolIOEnqueue( IntPtr NativeOverlapped, @@ -243,6 +258,10 @@ private unsafe void ThreadPoolIOEnqueue( // TODO: This event is fired for minor compat with CoreCLR in this case. Consider removing this method and use // FrameworkEventSource's thread transfer send/receive events instead at callers. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] [MethodImpl(MethodImplOptions.NoInlining)] public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle) @@ -253,6 +272,10 @@ public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle) } } +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(64, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IODequeue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)] private unsafe void ThreadPoolIODequeue( IntPtr NativeOverlapped, From 6d51f1221f8fb846f151387516f44f685a5e6d15 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 4 Mar 2021 10:18:11 -0800 Subject: [PATCH 17/24] excluding NativeRTEventSrc from being build in a project --- .../System.Private.CoreLib.Generators.csproj | 6 +++++- .../NativeRuntimeEventSource.PortableThreadPool.cs | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/generators/System.Private.CoreLib.Generators.csproj b/src/libraries/System.Private.CoreLib/generators/System.Private.CoreLib.Generators.csproj index 9b241b14aaf42..17d98413268e5 100644 --- a/src/libraries/System.Private.CoreLib/generators/System.Private.CoreLib.Generators.csproj +++ b/src/libraries/System.Private.CoreLib/generators/System.Private.CoreLib.Generators.csproj @@ -10,7 +10,11 @@ - + + + + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs index dc0278d4f975a..e4566eed9c4cf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs @@ -139,7 +139,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentSample( } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = EventSourceSuppressMessage)] #endif [Event(55, Level = EventLevel.Informational, Message = Messages.WorkerThreadAdjustmentAdjustment, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Adjustment, Version = 0, Keywords = Keywords.ThreadingKeyword)] @@ -170,7 +170,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentAdjustment( } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = EventSourceSuppressMessage)] #endif [Event(56, Level = EventLevel.Verbose, Message = Messages.WorkerThreadAdjustmentStats, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Stats, Version = 0, Keywords = Keywords.ThreadingKeyword)] @@ -229,7 +229,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentStats( } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = EventSourceSuppressMessage)] #endif [Event(63, Level = EventLevel.Verbose, Message = Messages.IOEnqueue, Task = Tasks.ThreadPool, Opcode = Opcodes.IOEnqueue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)] @@ -259,7 +259,7 @@ private unsafe void ThreadPoolIOEnqueue( // TODO: This event is fired for minor compat with CoreCLR in this case. Consider removing this method and use // FrameworkEventSource's thread transfer send/receive events instead at callers. #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = EventSourceSuppressMessage)] #endif [NonEvent] @@ -273,7 +273,7 @@ public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle) } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = EventSourceSuppressMessage)] #endif [Event(64, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IODequeue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)] From 05408097c6ec0f149831fd312fa1a6f0cd6259cd Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 4 Mar 2021 11:13:45 -0800 Subject: [PATCH 18/24] Missed couple of supppressions on NativeRTEventSrc --- .../NativeRuntimeEventSource.PortableThreadPool.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs index 7fd084066caa8..3f79244e9a9f3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs @@ -70,6 +70,10 @@ public enum ThreadAdjustmentReasonMap : uint ThreadTimedOut } +#if !ES_BUILD_STANDALONE + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [NonEvent] private unsafe void WriteThreadEvent(int eventId, uint numExistingThreads) { @@ -126,6 +130,10 @@ public void ThreadPoolWorkerThreadWait( } } +#if !ES_BUILD_STANDALONE + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(54, Level = EventLevel.Informational, Message = Messages.WorkerThreadAdjustmentSample, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Sample, Version = 0, Keywords = Keywords.ThreadingKeyword)] public unsafe void ThreadPoolWorkerThreadAdjustmentSample( double Throughput, @@ -265,10 +273,6 @@ private unsafe void ThreadPoolIOEnqueue( // TODO: This event is fired for minor compat with CoreCLR in this case. Consider removing this method and use // FrameworkEventSource's thread transfer send/receive events instead at callers. -#if !ES_BUILD_STANDALONE - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", - Justification = EventSourceSuppressMessage)] -#endif [NonEvent] [MethodImpl(MethodImplOptions.NoInlining)] public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle) From f0ca444f060ca39a41be26493237135578be6dcf Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 4 Mar 2021 13:37:29 -0800 Subject: [PATCH 19/24] build break fixes --- .../NetEventSource.Security.Windows.cs | 6 +++++ .../NetEventSource.Security.Windows.cs | 4 ++++ .../System/Buffers/ArrayPoolEventSource.cs | 4 ++++ .../Tracing/TraceLogging/SimpleEventTypes.cs | 4 ++++ .../Tracing/TraceLogging/SimpleTypeInfos.cs | 2 ++ .../Tracing/TraceLogging/Statics.cs | 2 ++ .../TraceLogging/TraceLoggingEventTypes.cs | 8 +++++++ .../TraceLogging/TraceLoggingTypeInfo.cs | 2 ++ ...veRuntimeEventSource.PortableThreadPool.cs | 4 ++++ .../src/Internal/DataflowEtwProvider.cs | 24 +++++++++++-------- .../Transactions/TransactionsEtwProvider.cs | 2 ++ 11 files changed, 52 insertions(+), 10 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 77ef71b94d359..eeb707b3496a1 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 @@ -9,8 +9,10 @@ namespace System.Net { internal sealed partial class NetEventSource { +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "parameter intent is an enum and is trimmer safe")] +#endif [Event(AcquireDefaultCredentialId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void AcquireDefaultCredential(string packageName, Interop.SspiCli.CredentialUse intent) { @@ -62,8 +64,10 @@ public void AcceptSecurityContext(SafeFreeCredentials? credential, SafeDeleteCon private void AcceptSecurityContext(string credential, string context, Interop.SspiCli.ContextFlags inFlags) => WriteEvent(AcceptSecuritContextId, credential, context, (int)inFlags); +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "parameter errorCode is an enum and is trimmer safe")] +#endif [Event(OperationReturnedSomethingId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void OperationReturnedSomething(string operation, Interop.SECURITY_STATUS errorCode) { @@ -73,8 +77,10 @@ public void OperationReturnedSomething(string operation, Interop.SECURITY_STATUS } } +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "parameter errorCode is an enum and is trimmer safe")] +#endif [Event(SecurityContextInputBufferId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void SecurityContextInputBuffer(string context, int inputBufferSize, int outputBufferSize, Interop.SECURITY_STATUS errorCode) { diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs b/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs index 12694700cf8a3..1d6b61bbf9191 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.Windows.cs @@ -9,8 +9,10 @@ namespace System.Net { internal sealed partial class NetEventSource { +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "parameter intent is an enum and is trimmer safe")] +#endif [Event(AcquireDefaultCredentialId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void AcquireDefaultCredential(string packageName, Interop.SspiCli.CredentialUse intent) { @@ -62,8 +64,10 @@ public void AcceptSecurityContext(SafeFreeCredentials? credential, SafeDeleteCon private void AcceptSecurityContext(string credential, string context, Interop.SspiCli.ContextFlags inFlags) => WriteEvent(AcceptSecuritContextId, credential, context, (int)inFlags); +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "parameter errorCode is an enum and is trimmer safe")] +#endif [Event(OperationReturnedSomethingId, Keywords = Keywords.Default, Level = EventLevel.Informational)] public void OperationReturnedSomething(string operation, Interop.SECURITY_STATUS errorCode) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs index e7a72fbd7b585..7fb9e54b6bb85 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs @@ -129,6 +129,10 @@ internal unsafe void BufferAllocated(int bufferId, int bufferSize, int poolId, i /// /// Event raised when a buffer returned to the pool is dropped. /// +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = EventSourceSuppressMessage)] +#endif [Event(6, Level = EventLevel.Informational)] internal unsafe void BufferDropped(int bufferId, int bufferSize, int poolId, int bucketId, BufferDroppedReason reason) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs index db4ea1db0e808..4a90f83287d75 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs @@ -27,11 +27,15 @@ internal static class SimpleEventTypes public static TraceLoggingEventTypes Instance { +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif get { return instance ??= InitInstance(); } } +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif private static TraceLoggingEventTypes InitInstance() { var info = TraceLoggingTypeInfo.GetInstance(typeof(T), null); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs index 4cfd9b929ae08..880c9a5941fd5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs @@ -271,7 +271,9 @@ internal sealed class NullableTypeInfo : TraceLoggingTypeInfo { private readonly TraceLoggingTypeInfo valueInfo; +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif public NullableTypeInfo(Type type, List recursionCheck) : base(type) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs index 1045dd294e102..04d6843d3dc45 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs @@ -381,7 +381,9 @@ public static bool IsGenericMatch(Type type, object? openType) return type.IsGenericType && type.GetGenericTypeDefinition() == (Type?)openType; } +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif public static TraceLoggingTypeInfo CreateDefaultTypeInfo( Type dataType, List recursionCheck) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs index 96b25e24d7a09..c8367baf80f96 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs @@ -48,7 +48,9 @@ public class TraceLoggingEventTypes /// /// The types of the fields in the event. This value must not be null. /// +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif internal TraceLoggingEventTypes( string name, EventTags tags, @@ -83,7 +85,9 @@ internal TraceLoggingEventTypes( { } +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif internal TraceLoggingEventTypes( string name, EventTags tags, @@ -182,7 +186,9 @@ internal NameInfo GetNameInfo(string name, EventTags tags) => this.nameInfos.TryGet(new KeyValuePair(name, tags)) ?? this.nameInfos.GetOrAdd(new NameInfo(name, tags, this.typeMetadata.Length)); +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif private static TraceLoggingTypeInfo[] MakeArray(System.Reflection.ParameterInfo[] paramInfos) { if (paramInfos == null) @@ -200,7 +206,9 @@ private static TraceLoggingTypeInfo[] MakeArray(System.Reflection.ParameterInfo[ return result; } +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif private static TraceLoggingTypeInfo[] MakeArray(Type[] types) { if (types == null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs index ebd23e9d9060b..8a699e243fc37 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs @@ -153,7 +153,9 @@ public abstract void WriteMetadata( [ThreadStatic] // per-thread cache to avoid synchronization private static Dictionary? threadCache; +#if !ES_BUILD_STANDALONE [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource WriteEvent 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")] +#endif public static TraceLoggingTypeInfo GetInstance(Type type, List? recursionCheck) { Dictionary cache = threadCache ??= new Dictionary(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs index 3f79244e9a9f3..ae4cda4813595 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/NativeRuntimeEventSource.PortableThreadPool.cs @@ -318,6 +318,10 @@ public void ThreadPoolIODequeue(RegisteredWaitHandle registeredWaitHandle) } } +#if !ES_BUILD_STANDALONE + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = EventSourceSuppressMessage)] +#endif [Event(60, Level = EventLevel.Verbose, Message = Messages.WorkingThreadCount, Task = Tasks.ThreadPoolWorkingThreadCount, Opcode = EventOpcode.Start, Version = 0, Keywords = Keywords.ThreadingKeyword)] public unsafe void ThreadPoolWorkingThreadCount(uint Count, ushort ClrInstanceID = DefaultClrInstanceId) { 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 3cce48e100196..9318c850a2688 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs @@ -60,7 +60,7 @@ private DataflowEtwProvider() { } // Dataflow Events // - #region Block Creation +#region Block Creation /// Trace an event for when a new block is instantiated. /// The dataflow block that was created. /// The options with which the block was created. @@ -83,9 +83,9 @@ private void DataflowBlockCreated(string blockName, int blockId) { WriteEvent(DATAFLOWBLOCKCREATED_EVENTID, blockName, blockId); } - #endregion +#endregion - #region Task Launching +#region Task Launching /// Trace an event for a block launching a task to handle messages. /// The owner block launching a task. /// The task being launched for processing. @@ -105,8 +105,10 @@ internal void TaskLaunchedForMessageHandling( } } +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "WriteEvent Parameters are trimmer safe")] +#endif [Event(TASKLAUNCHED_EVENTID, Level = EventLevel.Informational)] private void TaskLaunchedForMessageHandling(int blockId, TaskLaunchedReason reason, int availableMessages, int taskId) { @@ -121,9 +123,9 @@ internal enum TaskLaunchedReason /// A task is being launched to offer outgoing messages to linked targets. OfferingOutputMessages = 2, } - #endregion +#endregion - #region Block Completion +#region Block Completion /// Trace an event for a block completing. /// The block that's completing. [NonEvent] @@ -162,16 +164,18 @@ internal enum BlockCompletionReason Canceled = (int)TaskStatus.Canceled } +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "WriteEvent Parameters are trimmer safe")] +#endif [Event(BLOCKCOMPLETED_EVENTID, Level = EventLevel.Informational)] private void DataflowBlockCompleted(int blockId, BlockCompletionReason reason, string exceptionData) { WriteEvent(BLOCKCOMPLETED_EVENTID, blockId, reason, exceptionData); } - #endregion +#endregion - #region Linking +#region Linking /// Trace an event for a block linking. /// The source block linking to a target. /// The target block being linked from a source. @@ -191,9 +195,9 @@ private void DataflowBlockLinking(int sourceId, int targetId) { WriteEvent(BLOCKLINKED_EVENTID, sourceId, targetId); } - #endregion +#endregion - #region Unlinking +#region Unlinking /// Trace an event for a block unlinking. /// The source block unlinking from a target. /// The target block being unlinked from a source. @@ -214,7 +218,7 @@ private void DataflowBlockUnlinking(int sourceId, int targetId) { WriteEvent(BLOCKUNLINKED_EVENTID, sourceId, targetId); } - #endregion +#endregion } #endif } 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 b1bb0e446ff95..b97fb8f6a8ecb 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs @@ -839,8 +839,10 @@ internal void TransactionScopeCreated(TransactionTraceIdentifier transactionID, } } +#if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "TransactionScopeResult parameter is an enum and is trimmer safe")] +#endif [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 a91e900d6ac88b1f19ffed91757fe49742d25646 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 14 Apr 2021 08:04:56 -0700 Subject: [PATCH 20/24] Trimmer warning fix related to EventSource manifest creation --- .../ref/System.Diagnostics.Tracing.cs | 1 + .../src/ILLink/ILLink.Suppressions.Shared.xml | 6 ------ .../src/System/Diagnostics/Tracing/EventSource.cs | 9 ++++++++- 3 files changed, 9 insertions(+), 7 deletions(-) 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..7c8ba5aeeb496 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,7 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute /// } /// /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] public partial class EventSource : IDisposable { @@ -2763,9 +2764,15 @@ private void EnsureDescriptorsInitialized() #endif if (m_eventData == null) { +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Derived type members are safe")] +#endif + byte[]? GetCreateManifestAndDescriptorsViaLocalMethod(string name) => CreateManifestAndDescriptors(this.GetType(), name, this); + // get the metadata via reflection. Debug.Assert(m_rawManifest == null); - m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this); + m_rawManifest = GetCreateManifestAndDescriptorsViaLocalMethod(Name); Debug.Assert(m_eventData != null); // TODO Enforce singleton pattern From 86ce794134a28e2dec5729a64120ff556952593e Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 14 Apr 2021 11:25:24 -0700 Subject: [PATCH 21/24] incorporate fb --- .../src/System/Diagnostics/Tracing/EventSource.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 7c8ba5aeeb496..93fa325350f82 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,7 +227,9 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute /// } /// /// - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] +#if !ES_BUILD_STANDALONE + [DynamicallyAccessedMembers(ManifestMemberTypes)] +#endif public partial class EventSource : IDisposable { @@ -2766,7 +2768,9 @@ private void EnsureDescriptorsInitialized() { #if !ES_BUILD_STANDALONE [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "Derived type members are safe")] + 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.")] #endif byte[]? GetCreateManifestAndDescriptorsViaLocalMethod(string name) => CreateManifestAndDescriptors(this.GetType(), name, this); From 2fd2f6f71b971405ad0941f2ac33d9377832b62c Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 15 Apr 2021 07:42:13 -0700 Subject: [PATCH 22/24] fix build break in some configs --- .../src/System/Diagnostics/Tracing/EventSource.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 93fa325350f82..be8dc93dcb882 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 @@ -2766,17 +2766,18 @@ private void EnsureDescriptorsInitialized() #endif if (m_eventData == null) { + // 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.")] -#endif byte[]? GetCreateManifestAndDescriptorsViaLocalMethod(string name) => CreateManifestAndDescriptors(this.GetType(), name, this); - - // get the metadata via reflection. - Debug.Assert(m_rawManifest == null); m_rawManifest = GetCreateManifestAndDescriptorsViaLocalMethod(Name); +#else + m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this); +#endif Debug.Assert(m_eventData != null); // TODO Enforce singleton pattern From a87e45264f36c4027a3ee93bd057e8f166fd1183 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 19 Apr 2021 15:37:19 -0700 Subject: [PATCH 23/24] comment feedback --- .../src/System/Diagnostics/Tracing/EventSource.cs | 2 ++ 1 file changed, 2 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 be8dc93dcb882..3e0a06fa522f8 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 @@ -228,6 +228,8 @@ 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 From 1790705ce24d0b7ff8b931a96414d3877023f0a0 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 19 Apr 2021 16:11:54 -0700 Subject: [PATCH 24/24] build break --- .../src/System/Diagnostics/Tracing/EventSource.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 3e0a06fa522f8..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 @@ -228,8 +228,8 @@ 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. + // 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