Skip to content

Unnecessary warnings for DiagnosticSourceEventSource #2136

Closed
@eerhardt

Description

@eerhardt

dotnet publish the following application:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>

</Project>
using System;
using System.Xml;

class Program
{
    static void Main(string[] args)
    {
        XmlDocument doc = new();
        doc.LoadXml("<hello />");
        Console.WriteLine(doc.InnerXml);
    }
}

Expected results

There shouldn't be any ILLink warnings, since I am not using code that is unsafe.

Actual results

ILLink : Trim analysis warning IL2026: System.Diagnostics.DiagnosticSourceEventSource: Using method 'System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.Morph(Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type of object being written to DiagnosticSource cannot be discovered statically. [C:\DotNetTest\HelloWorld\HelloWorld.csproj]
ILLink : Trim analysis warning IL2026: System.Diagnostics.DiagnosticSourceEventSource: Using method 'System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.PropertySpec.Fetch(Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type of object being written to DiagnosticSource cannot be discovered statically. [C:\DotNetTest\HelloWorld\HelloWorld.csproj]
ILLink : Trim analysis warning IL2026: System.Diagnostics.DiagnosticSourceEventSource: Using method 'System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.Morph(Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type of object being written to DiagnosticSource cannot be discovered statically. [C:\DotNetTest\HelloWorld\HelloWorld.csproj]
ILLink : Trim analysis warning IL2026: System.Diagnostics.DiagnosticSourceEventSource: Using method 'System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.MakeImplicitTransforms(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type of object being written to DiagnosticSource cannot be discovered statically. [C:\DotNetTest\HelloWorld\HelloWorld.csproj]
ILLink : Trim analysis warning IL2026: System.Diagnostics.DiagnosticSourceEventSource: Using method 'System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.PropertySpec.PropertyFetch.FetcherForProperty(Type,String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type of object being written to DiagnosticSource cannot be discovered statically. [C:\DotNetTest\HelloWorld\HelloWorld.csproj]

Notes

The APIs that are getting warned about all either have RequiresUnreferencedCodeAttribute or UnconditionalSuppressMessage, so I don't understand why the linker is warning here. All those methods are internal implementation details of DiagnosticSourceEventSource. See the code here:

https://github.com/dotnet/runtime/blob/2be4fdc81f7f190ac35646ccc18799deb05da7dd/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs#L650-L661

As far as I can tell, DiagnosticSource is referenced by System.Net.Http, which is referenced by XmlDownloadManager. However, when I used HttpClient by itself in an app, I couldn't get the warnings to show up.

cc @vitek-karas @sbomer @marek-safar

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions