CS8795 Showing When it Shouldn't

See original GitHub issue

Not 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sharwellcommented, Feb 18, 2022

@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).

1reaction
jasonmalinowskicommented, Feb 4, 2022

@stap123 Awesome, thanks for following up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Partial platform specific methods in .NET MAUI
(CS8795)". It seems like the platform specific files are not seen by the compiler? Note, they are in a separate assembly project from...
Read more >
How to Solve Partial method must have an implementation ...
Hi, How can I solve this error: Partial method must have an implementation part because it has accessibility modifiers. in the below code: ......
Read more >
Introducing C# 9: Extending Partial Methods
Partial methods must have a void return type; Partial methods can't have out parameters; Partial methods can't have any accessibility keyword ( ...
Read more >
GeneratedRegex in static class : r/csharp
Error CS8795 Partial method 'NumberHelper.NumberRegex()' must have an implementation part because it has accessibility modifiers.
Read more >
[LoggerMessage] fail when build with sonarscanner
When using [LoggerMessage] and source generator for logs, sonar doesn't find the generated code. CS8795: Partial method '.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found