-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
Milestone
Description
Description
Adding a SuppressMessageAttribute to a method marked with LoggerMessageAttribute results in a failed compilation
Reproduction Steps
- Create a new Class Library
- Add
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.1" /> - Write the following code in Class1.cs
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
namespace ClassLibrary1
{
public partial class Class1
{
private ILogger _logger;
public Class1(ILogger logger) => _logger = logger;
[LoggerMessage(EventId = 1, Level = LogLevel.Error, Message = "Log Message {Name}")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
private partial void LogError(string Name, Exception exception);
}
}- Build
Expected behavior
The source generator should generate.
Actual behavior
The source generator fails with an error in the build log:
CSC : warning CS8785: Generator 'LoggerMessageGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'InvalidCastException' with message 'Unable to cast object of type 'System.String' to type 'System.Int32'.'
Regression?
No response
Known Workarounds
No response
Configuration
dotnet SDK version: 6.0.103
OS: Manjaro Linux (x64)
Other information
No response
Reactions are currently unavailable