Skip to content

Suppress obsolete warnings in the static generator output - #1144

Open
akashchamp wants to merge 1 commit into
aaubry:masterfrom
akashchamp:fix-obsolete-warnings-static-generator
Open

akashchamp wants to merge 1 commit into
aaubry:masterfrom
akashchamp:fix-obsolete-warnings-static-generator

Conversation

@akashchamp

Copy link
Copy Markdown

Fixes #1096

The static generator references every member of a [YamlSerializable] type in YamlDotNetAutoGraph.g.cs, so an [Obsolete] type or property produced CS0612/CS0618 in generated code that the user can not edit. With TreatWarningsAsErrors that fails the build.

This adds #pragma warning disable CS0612 and CS0618 to the generated file header, next to the nullability warnings it already disables. I also added an [Obsolete] class and two [Obsolete] properties (with and without a message) to YamlDotNet.Core7AoTCompileTest, which already builds with TreatWarningsAsErrors, so CI catches a regression.

Verified locally with the .NET 10.0.401 SDK:

  • On master with only the new test types, dotnet build YamlDotNet.Core7AoTCompileTest -c Release fails with 70 CS0612/CS0618 errors, all in YamlDotNetAutoGraph.g.cs.
  • With the fix it builds with 0 warnings and 0 errors, and the generated header contains the two new pragmas.
  • dotnet build YamlDotNet.sln -c Release succeeds, and dotnet test YamlDotNet.Test -c Release passes (2013/2013 on net8.0 and net10.0).

The generated code references every member of a [YamlSerializable] type, so an [Obsolete] type or property produced CS0612/CS0618 in YamlDotNetAutoGraph.g.cs and broke builds with TreatWarningsAsErrors. Disable both warnings alongside the ones the generator already suppresses, and add obsolete members to the AoT compile test so the build catches a regression.

Fixes aaubry#1096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated code for YamlStaticContext produces warnings for obsolete type members

1 participant