dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.87k stars 4.01k forks source link

CS8795 reported when expression with reference to another assembly happen #73964

Closed trejjam closed 1 month ago

trejjam commented 2 months ago

Version Used: .Net 8

Steps to Reproduce:

  1. Clone https://github.com/trejjam/riok-mapperly/blob/feature/failing-projection-with-static-mapper-from-another-assembly
  2. Open test/Riok.Mapperly.IntegrationTests/Mapper/UseExternalMapperFromAnotherAssembly.cs in VS Code/VS/Rider (Tested in all these, VS Code 1.90, with C# Dev Kit v1.6.8; VS 2022 17.10.2; Rider 2024.1.3, 2024.2 EAP2)
  3. See CS8795 on line 12, 14 and in other source generated code as well

Diagnostic Id: CS8795 Partial method UseExternalMapperFromAnotherAssembly.ProjectToTarget(IQueryable<UseExternalMapperFromAnotherAssembly.Source>) must have an implementation part because it has accessibility modifiers.

Expected Behavior: There will be no CS8795 since the project compiles normally. It seems like a bug in the C# language server.

Actual Behavior: Error CS8795 is reported.

The error goes away when:

image image image image

ToddGrun commented 2 months ago

@jasonmalinowski -- Do you have any context here? Same analyzer id as https://github.com/dotnet/roslyn/issues/65850 and same repo as https://github.com/dotnet/roslyn/issues/69522

trejjam commented 1 month ago

The issue is not with Roslyn.

If anyone hits a similar issue, the problem is that in "IDE" mode, you have a dependency as CompilationReference (a link to Compilation of your dependencies) rather than the final assembly of your dependency. Due to that, you need special handling at some places when processing SyntaxTrees from your dependencies.