Suppress trim warnings
authorSven Boemer <sbomer@gmail.com>
Tue, 7 Jun 2022 23:25:56 +0000 (16:25 -0700)
committerSven Boemer <sbomer@gmail.com>
Tue, 7 Jun 2022 23:29:43 +0000 (16:29 -0700)
For trim annotations which reference compiler-generated code

src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/Types.cs

index 6776734..a8d700d 100644 (file)
@@ -660,6 +660,9 @@ namespace System.Diagnostics
 
                         [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
                             Justification = "DiagnosticSource.Write is marked with RequiresUnreferencedCode.")]
+                        [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2119",
+                            Justification = "DAM on EventSource references this compiler-generated local function which calls a " +
+                                            "method that requires unreferenced code. EventSource will not access this local function.")]
                         void OnEventWritten(KeyValuePair<string, object?> evnt)
                         {
                             // The filter given to the DiagnosticSource may not work if users don't is 'IsEnabled' as expected.
index 7db1b78..199bf2d 100644 (file)
@@ -2206,6 +2206,9 @@ namespace System.Diagnostics.Tracing
 #if !ES_BUILD_STANDALONE
                 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
                     Justification = "The call to TraceLoggingEventTypes with the below parameter values are trim safe")]
+                [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2119",
+                    Justification = "DAM on EventSource references this compiler-generated local function which calls a " +
+                                    "constructor that requires unreferenced code. EventSource will not access this local function.")]
 #endif
                 static TraceLoggingEventTypes GetTrimSafeTraceLoggingEventTypes() =>
                     new TraceLoggingEventTypes(EventName, EventTags.None, new Type[] { typeof(string) });
index 2976184..8f7a458 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Threading;
+using System.Diagnostics.CodeAnalysis;
 
 namespace System.Diagnostics.Tracing
 {
@@ -66,6 +67,9 @@ namespace System.Diagnostics.Tracing
             base.WriteEvent((int)EventId.AppContextSwitch, switchName, value);
         }
 
+        [UnconditionalSuppressMessage ("ReflectionAnalysis", "IL2119",
+            Justification = "DAM on EventSource references the compiler-generated lambda methods some of which call PInvokes " +
+                            "which are considered potentially dangerous. Event source will not use these lambdas.")]
         protected override void OnEventCommand(EventCommandEventArgs command)
         {
             if (command.Command == EventCommand.Enable)
index f255598..b5bfbbb 100644 (file)
@@ -625,6 +625,10 @@ namespace System.Runtime.Serialization
 
     internal sealed class DateTimeDataContract : PrimitiveDataContract
     {
+        [UnconditionalSuppressMessage ("ReflectionAnalysis", "IL2118",
+            Justification = "DAM on the first parameter of the PrimitiveDataContract constructor references methods of DateTime, " +
+                            "which has a compiler-generated local function LowGranularityNonCachedFallback that calls PInvokes " +
+                            "which are considered potentially dangerous. Data contract serialization will not access this local function.")]
         public DateTimeDataContract() : base(typeof(DateTime), DictionaryGlobals.DateTimeLocalName, DictionaryGlobals.SchemaNamespace)
         {
         }
index 5d0e765..5f0ee4a 100644 (file)
@@ -510,6 +510,10 @@ namespace System.Xml.Serialization
             "token"
         };
 
+        [UnconditionalSuppressMessage ("ReflectionAnalysis", "IL2118",
+            Justification = "DAM on AddPrimitive references methods of DateTime, which has a compiler-generated local function " +
+                            "LowGranularityNonCachedFallback that calls PInvokes which are considered potentially dangerous. " +
+                            "XML serialization will not access this local function.")]
         static TypeScope()
         {
             AddPrimitive(typeof(string), "string", "String", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Reference | TypeFlags.HasDefaultConstructor);
@@ -605,6 +609,10 @@ namespace System.Xml.Serialization
             return false;
         }
 
+        [UnconditionalSuppressMessage ("ReflectionAnalysis", "IL2118",
+            Justification = "DAM on AddPrimitive references methods of DateTime, which has a compiler-generated local function " +
+                            "LowGranularityNonCachedFallback that calls PInvokes which are considered potentially dangerous. " +
+                            "XML serialization will not access this local function.")]
         private static void AddSoapEncodedTypes(string ns)
         {
             AddSoapEncodedPrimitive(typeof(string), "normalizedString", ns, "String", new XmlQualifiedName("normalizedString", XmlSchema.Namespace), TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.Reference | TypeFlags.HasDefaultConstructor);