Skip to content

YamlDotNet 16.2.0 produces trim warnings, while YamlDotNet 13.1.0 does not #1012

Description

@hach-que

Describe the bug
When building a trimmed executable against YamlDotNet 13.1.0, the .NET linker is able to successfully build. After upgrading to YamlDotNet 16.2.0, linking now fails with:

/Users/runner/.nuget/packages/yamldotnet/16.2.0/lib/net8.0/YamlDotNet.dll : error IL2104: Assembly 'YamlDotNet' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [/Users/runner/work/uet/uet/UET/uet/uet.csproj]

To Reproduce
Create a project that has these dependencies:

<PackageReference Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" Version="13.0.2" />
<PackageReference Include="YamlDotNet" Version="13.1.0" />

and enable trim warnings and other analyzers with:

  <PropertyGroup>
    <IsTrimmable>true</IsTrimmable>
    <EnableTrimAnalyzer>true</EnableTrimAnalyzer>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
    <AnalysisLevel>latest</AnalysisLevel>
    <AnalysisMode>All</AnalysisMode>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
  </PropertyGroup>

The project will build successfully. Now modify the project dependencies to:

<PackageReference Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" Version="16.2.0" />
<PackageReference Include="YamlDotNet" Version="16.2.0" />

and it will fail with that trim warning.

This issue could be caught in the YamlDotNet build process by adding the following property to the YamlDotNet project, though it will likely generate a bunch of warnings on dynamic APIs that either need to be addressed or silenced:

<PropertyGroup>
    <EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions