CS8795 Showing When it Shouldn't
See original GitHub issueNot sure if this is the right repo if not let me know and I can move.
When using the new LoggerMessage attribute we get errors all over the place even though this is working correctly. In case it’s relevant we use partial classes to keep the individual messages close to the code that actually uses them rather than having a single huge Log class in one place.
There is also a similar/related report on Dev Communitey here: https://developercommunity.visualstudio.com/t/issue-when-using-loggermessage-and-static-extensio/1638197
Version:
VS2022 Current (17.0.5)
Steps to Reproduce:
Put this in a new console app and install the NuGet package Microsoft.Extensions.Logging you should see the error CS8795 Partial method ‘Log.Example(ILogger)’ must have an implementation part because it has accessibility modifiers.
using Microsoft.Extensions.Logging;
internal static partial class Log
{
[LoggerMessage(
EventId = 0,
Level = LogLevel.Warning,
Message = "A message",
SkipEnabledCheck = true)]
public static partial void Example(this ILogger logger);
}
Expected Behavior:
There should be no error shown as this is valid code because the attribute generates the code.
Actual Behavior:
The error is shown.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:21 (11 by maintainers)
Top Related StackOverflow Question
@stap123 This is probably caused by an exception in the generator (or the generator driver). Currently it’s not possible to see those exceptions (#54098), which makes it difficult to fix. The generator also doesn’t recover from those errors until you reload the project or restart the IDE (#58625).
@stap123 Awesome, thanks for following up!