-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging Source Generator fails with a InvalidCastException #67167
Comments
Tagging subscribers to this area: @dotnet/area-extensions-logging Issue DetailsDescriptionAdding a SuppressMessageAttribute to a method marked with LoggerMessageAttribute results in a failed compilation Reproduction Steps
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);
}
}
Expected behaviorThe source generator should generate. Actual behaviorThe 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 WorkaroundsNo response Configurationdotnet SDK version: 6.0.103 Other informationNo response
|
@theit8514 would you please try this with the newer preview version? |
Tested with sdk version 7.0.100-preview.2.22153.17 and targeting net7.0 and referencing package Microsoft.Extensions.Logging.Abstractions version 7.0.0-preview.2.22152.2. Same build error.
|
Thanks will take a look |
- alongside LoggerMessageAttribute Fixes dotnet#67167
- alongside LoggerMessageAttribute Fixes #67167
@theit8514 thanks for the report, the fix should be available for preview 4. |
- alongside LoggerMessageAttribute Fixes dotnet#67167
- alongside LoggerMessageAttribute Fixes dotnet#67167
Description
Adding a SuppressMessageAttribute to a method marked with LoggerMessageAttribute results in a failed compilation
Reproduction Steps
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.1" />
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
The text was updated successfully, but these errors were encountered: