Description
In .NET 11, the LoggerMessage source generator has been refactored to support proper incremental building, significantly improving source generator performance by avoiding full re-runs on every compilation change. As a side effect of this refactoring, the generator now uses DiagnosticInfo.GetTrimmedLocation which creates diagnostic locations without SyntaxTree references. This breaks #pragma warning disable matching for diagnostics emitted by the logging source generator (e.g., SYSLIB1002, SYSLIB1013, SYSLIB1018). The System.Text.Json source generator already had this same limitation.
This change was introduced in dotnet/runtime#124077. For more context on why #pragma directive suppression is incompatible with incremental source generator builds, see dotnet/runtime#92509 and dotnet/roslyn#68291.
Version
.NET 11 Preview 2
Previous behavior
Users could use #pragma warning disable directives in source code to suppress diagnostics emitted by the LoggerMessage source generator, such as:
#pragma warning disable SYSLIB1002
#pragma warning disable SYSLIB1013
#pragma warning disable SYSLIB1018
The compiler would match the pragma directives to the diagnostic locations and suppress them as expected.
New behavior
#pragma warning disable directives no longer suppress diagnostics emitted by the LoggerMessage source generator. The diagnostics are still reported but the compiler cannot match them to pragma directives because the diagnostic locations are created without SyntaxTree references (via DiagnosticInfo.GetTrimmedLocation).
This aligns the LoggerMessage behavior with the other source generators like System.Text.Json source generator, which already had this same limitation.
Type of breaking change
Reason for change
The change was made to improve the incrementality of the LoggerMessage source generator. Previously, the generator was passing Compilation through its pipeline, causing full re-runs on every compilation change rather than only when attributed syntax nodes changed. The refactoring to follow proper incremental generator patterns involved using DiagnosticInfo with trimmed locations (without SyntaxTree references) as a side effect.
See dotnet/runtime#124077 and dotnet/runtime#76119 for details.
Recommended action
Use project-level <NoWarn> in MSBuild instead of #pragma warning disable directives to suppress LoggerMessageGenerator diagnostics:
<PropertyGroup>
<NoWarn>$(NoWarn);SYSLIB1002;SYSLIB1013;SYSLIB1018</NoWarn>
</PropertyGroup>
Alternatively, use the .editorconfig file to suppress diagnostics:
[*.cs]
dotnet_diagnostic.SYSLIB1002.severity = none
dotnet_diagnostic.SYSLIB1013.severity = none
dotnet_diagnostic.SYSLIB1018.severity = none
Feature area
Extensions
Affected APIs
Microsoft.Extensions.Logging.LoggerMessageAttribute
Associated WorkItem - 552969
Description
In .NET 11, the
LoggerMessagesource generator has been refactored to support proper incremental building, significantly improving source generator performance by avoiding full re-runs on every compilation change. As a side effect of this refactoring, the generator now usesDiagnosticInfo.GetTrimmedLocationwhich creates diagnostic locations withoutSyntaxTreereferences. This breaks#pragma warning disablematching for diagnostics emitted by the logging source generator (e.g., SYSLIB1002, SYSLIB1013, SYSLIB1018). TheSystem.Text.Jsonsource generator already had this same limitation.This change was introduced in dotnet/runtime#124077. For more context on why #pragma directive suppression is incompatible with incremental source generator builds, see dotnet/runtime#92509 and dotnet/roslyn#68291.
Version
.NET 11 Preview 2
Previous behavior
Users could use
#pragma warning disabledirectives in source code to suppress diagnostics emitted by theLoggerMessagesource generator, such as:The compiler would match the pragma directives to the diagnostic locations and suppress them as expected.
New behavior
#pragma warning disabledirectives no longer suppress diagnostics emitted by theLoggerMessagesource generator. The diagnostics are still reported but the compiler cannot match them to pragma directives because the diagnostic locations are created withoutSyntaxTreereferences (viaDiagnosticInfo.GetTrimmedLocation).This aligns the
LoggerMessagebehavior with the other source generators likeSystem.Text.Jsonsource generator, which already had this same limitation.Type of breaking change
Reason for change
The change was made to improve the incrementality of the
LoggerMessagesource generator. Previously, the generator was passingCompilationthrough its pipeline, causing full re-runs on every compilation change rather than only when attributed syntax nodes changed. The refactoring to follow proper incremental generator patterns involved usingDiagnosticInfowith trimmed locations (withoutSyntaxTreereferences) as a side effect.See dotnet/runtime#124077 and dotnet/runtime#76119 for details.
Recommended action
Use project-level
<NoWarn>in MSBuild instead of#pragma warning disabledirectives to suppressLoggerMessageGeneratordiagnostics:Alternatively, use the
.editorconfigfile to suppress diagnostics:Feature area
Extensions
Affected APIs
Microsoft.Extensions.Logging.LoggerMessageAttributeAssociated WorkItem - 552969