Skip to content
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

Compile-time logging source generation example triggers analyzer error "partial method must have an implementation part because it has accessibility modifiers" #27471

Closed
wjrogers opened this issue Dec 9, 2021 · 29 comments
Assignees
Labels
dotnet-fundamentals/svc Pri2 product-question Product usage related questions [org][type][category] 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@wjrogers
Copy link

wjrogers commented Dec 9, 2021

When I write a class like the one in the example on this page,

public static partial class Log
{
    [LoggerMessage(
        EventId = 0,
        Level = LogLevel.Critical,
        Message = "Could not open socket to `{hostName}`")]
    public static partial void CouldNotOpenSocket(
        ILogger logger, string hostName);
}

the IDE flags it with an error:

Partial method 'void CouldNotOpenSocket(ILogger, string)' must have an implementation part because it has accessibility modifiers.

However, the code compiles and executes successfully. Will you please add some guidance to this page about this error, especially if there is a way to silence it?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 68965

@tdykstra
Copy link
Contributor

tdykstra commented Dec 9, 2021

@maryamariyan can you help with this question?

@tdykstra tdykstra added doc-enhancement Improve the current content [org][type][category] waiting-on-feedback Waiting for feedback from SMEs before they can be merged labels Dec 9, 2021
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label Dec 9, 2021
@maryamariyan
Copy link
Member

thanks will take a look

@maryamariyan
Copy link
Member

I got a repro for this. Thanks for your report @wjrogers.

@pranavkm what approach do you recommend to silence a diagnostic?

@pranavkm
Copy link
Contributor

@dotnetshadow
Copy link

dotnetshadow commented Dec 21, 2021

You could use a pragma warning suppress to do this: https://docs.microsoft.com/dotnet/fundamentals/code-analysis/suppress-warnings#use-a-preprocessor-directive

I did try the following but the error still came up

#pragma warning disable CS8795 // Rethrow to preserve stack details

Also the link to this doc produces an 404
https://docs.microsoft.com/en-us/dotnet/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error?f1url=%3FappId%3Droslyn%26k%3Dk(CS8795)

@maryamariyan
Copy link
Member

Also the link to this doc produces an 404
https://docs.microsoft.com/en-us/dotnet/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error?f1url=%3FappId%3Droslyn%26k%3Dk(CS8795)

FYI, this issue is tracked by #23900

@ds185357
Copy link

I got the same behavior. The code compiles successfully, but VS with static analysis enabled produces CS8795 and CA1822. The CA1822 can be suppressed, CS8795 cannot.
image

@stap123
Copy link
Contributor

stap123 commented Jan 11, 2022

I also get the CS8795 error for all methods. The project successfully compiles and works as expected but VS 2022 shows an error for every method.

I'm not sure this is actually a doc error and not a VS 2022 issue?

@seangwright
Copy link
Contributor

I experience this same issue. #pragma directives didn't solve it. However I was able to resolve the errors by authoring the code, then closing VS, and finally starting VS and opening the solution back up. No amount of rebuilding solutions/projects or closing/reopening files solved the issue. I had to restart VS.

I've noticed this same issue with other source generator related code/libraries and it was solved in the same way.

Note: I am using Visual Studio 17.1.1

@shashank-raut
Copy link

I can too confirm that closing and opening the Visual Studio solved this issue for me.
Visual Studio Details - Microsoft Visual Studio Professional 2022 (64-bit) - Current
Version 17.1.3

@jasonvasquez
Copy link

For what it's worth, I see this issue with Rider as well. I suspect it's not a Visual Studio issue specifically, but perhaps a Roslyn issue. (The same close and re-open workaround works with Rider)

@maryamariyan maryamariyan removed their assignment Jan 9, 2023
@RealDotNetDave
Copy link

I have the same issue, but only when the solution builds on Linux.

@tdykstra tdykstra added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Mar 4, 2023
@tdykstra
Copy link
Contributor

tdykstra commented Mar 4, 2023

@maryamariyan I can't repro this in VS 2022 17.5, so it seems to have been at least partially addressed, just not in Linux per @RealDotNetDave. That being the case it seems not to be a docs issue -- should I transfer this issue to the runtime repo?

@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Mar 7, 2023
@tdykstra
Copy link
Contributor

ping @maryamariyan

@tdykstra tdykstra self-assigned this Mar 14, 2023
@dbead
Copy link

dbead commented Mar 17, 2023

Seems fixed atm in 17.5.2 for me but was happening in 17.5.1 using dotnet 6.

@maryamariyan
Copy link
Member

cc @dotnet/area-extensions-logging

@layomia
Copy link
Contributor

layomia commented Mar 17, 2023

Thanks @maryamariyan.

@RealDotNetDave are you still seeing this issue on Linux with the latest VS version?

@wjrogers
Copy link
Author

I can't reproduce the error in VS 17.5.2, either. I notice that the generated source (visible in Solution Explorer under Dependencies > Analyzers) updates almost immediately after editing the LoggerMessage attribute, even without saving the file. A couple versions ago, I had noticed these generated sources didn't update until a complete Visual Studio restart. Possibly a related issue has been fixed?

@MrBildo
Copy link

MrBildo commented Apr 27, 2023

I'm still seeing this issue in 17.5.4. No amount of suppression makes it go away. I have NoWarn in my project. .serverity = none in .editorconfig. Like others, it'll go away for a little while then crop back up.

I'm seeing it using the https://mapperly.riok.app/ library which uses heavy source generation.

Edit: I'm not using Linux

@tdykstra
Copy link
Contributor

@layomia Given that it looks like this may still be an issue, is the runtime repo the right place to transfer this issue to?

@tarekgh
Copy link
Member

tarekgh commented Apr 28, 2023

This looks the same issue dotnet/roslyn#58913 and supposes to be fixed a while ago by dotnet/roslyn#58990.

@jasonmalinowski do you know why this still repro for the users?

CC @Youssef1313

@MrBildo
Copy link

MrBildo commented Apr 28, 2023

I'm happy to provide more details. Again, this is being triggered from a 3rd party library, which certainly is the underlying cause. However, I would expect to be able to suppress it in some way.

@Youssef1313
Copy link
Member

This is roslyn-related issue.

I see dotnet/roslyn#67123 which mentions:

IntelliSense not working correctly (red squiggly lines all over the place for generated members)

So this seems very similar.

@Youssef1313
Copy link
Member

Also there is dotnet/roslyn#65044

@tdykstra
Copy link
Contributor

tdykstra commented Oct 2, 2023

This looks the same issue dotnet/roslyn#58913 and supposes to be fixed a while ago by dotnet/roslyn#58990.

@jasonmalinowski do you know why this still repro for the users?

@tarekgh Can we close this as a duplicate of dotnet/roslyn#58913? It doesn't appear to be a doc issue.

@jasonmalinowski
Copy link
Member

Yeah, this is a product bug, so I'm not sure why we'd document workarounds rather than, well, fixing it.

@tarekgh
Copy link
Member

tarekgh commented Oct 2, 2023

Can we close this as a duplicate of dotnet/roslyn#58913? It doesn't appear to be a doc issue.

@MrBildo was claiming the issue is still reported from a third-party library #27471 (comment). If this is not the case anymore then we can close. Otherwise, it will be good if @MrBildo provide a repo if the issue is still showing up.

@MrBildo
Copy link

MrBildo commented Oct 2, 2023

In the case of Mapperly, the library I was using, it is no longer an issue, nor have I seen it recently with other source generators. Something fixed it along the way. I no longer have an issue. Regardless it doesn't seem like a doc problem.

@jasonmalinowski
Copy link
Member

Yep: if there's an issue here, the issue should be in the Roslyn repo as a bug, not a doc issue asking for a workaround. This can just be closed.

@tarekgh tarekgh closed this as completed Oct 2, 2023
@tdykstra tdykstra added product-question Product usage related questions [org][type][category] and removed waiting-on-feedback Waiting for feedback from SMEs before they can be merged doc-enhancement Improve the current content [org][type][category] labels Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-fundamentals/svc Pri2 product-question Product usage related questions [org][type][category] 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: Done
Development

No branches or pull requests