You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Logging Source Generator fails with a NullReferenceException #52277
usingSystem;usingMicrosoft.Extensions.Logging;namespaceClassLibrary1{publicpartialclassClass1{privateILogger_logger;publicClass1(ILoggerlogger)=>_logger=logger;internalstaticclassEventIds{publicconstintHealthCheckErrorId=100;}[LoggerMessage(EventId=HealthCheckErrorId,Level=LogLevel.Error,Message="Health check {HealthCheckName} threw an unhandled exception after {ElapsedMilliseconds}ms")]privatepartialvoidHealthCheckError(stringHealthCheckName,doubleElapsedMilliseconds,Exceptionexception);}}
Build
Actual results
I'm seeing the following warning in my Error List
Severity Code Description Project File Line Suppression State
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 'NullReferenceException' with message 'Object reference not set to an instance of an object.' ClassLibrary1 C:\Users\eerhardt\source\repos\ClassLibrary1\ClassLibrary1\CSC 1 Active
Expected results
I only expect my compile error (here I didn't put EventIds. in front of HealthCheckErrorId in the LoggerMessage attribute) to exist in the Error List. I don't expect the Logging Source Generator to fail and add more errors.
I only expect my compile error (here I didn't put EventIds. in front of HealthCheckErrorId in the LoggerMessage attribute) to exist in the Error List. I don't expect the Logging Source Generator to fail and add more errors.
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.
Activity
ericstj commentedon May 5, 2021
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.
maryamariyan commentedon Jun 23, 2021
Closed via PR #54305