-
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 NullReferenceException #52277
Comments
Tagging subscribers to this area: @maryamariyan Issue DetailsRepro
using System;
using Microsoft.Extensions.Logging;
namespace ClassLibrary1
{
public partial class Class1
{
private ILogger _logger;
public Class1(ILogger logger) => _logger = logger;
internal static class EventIds
{
public const int HealthCheckErrorId = 100;
}
[LoggerMessage(EventId = HealthCheckErrorId, Level = LogLevel.Error, Message = "Health check {HealthCheckName} threw an unhandled exception after {ElapsedMilliseconds}ms")]
private partial void HealthCheckError(string HealthCheckName, double ElapsedMilliseconds, Exception exception);
}
}
Actual resultsI'm seeing the following warning in my Error List
Expected resultsI only expect my compile error (here I didn't put
|
Agree with @eerhardt that we need to ensure our source generators are resilient to bad syntax in user's source files (cc @layomia in case similar concerns apply to Json). We probably need test cases for invalid source to ensure our generators handle these cases well. |
Closed via PR #54305 |
Repro
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0-preview.4.21222.10" />
Class1.cs
Actual results
I'm seeing the following warning in my Error List
Expected results
I only expect my compile error (here I didn't put
EventIds.
in front ofHealthCheckErrorId
in the LoggerMessage attribute) to exist in the Error List. I don't expect the Logging Source Generator to fail and add more errors.cc @maryamariyan
The text was updated successfully, but these errors were encountered: