dotnet / dotnet/roslyn

Roslyn shows false errors from missing source generated files after build

Open
#80,717 4 comments 0 reactions 1 assignee Claimed by @jasonmalinowski View on GitHub
Area-IDE Feature - Source Generators
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**:

Microsoft Visual Studio Professional
Version 17.14.16
Version 17.14.16 Preview 1.0
Version: 18.0.0 Insiders [11104.47]

**Steps to Reproduce**:

1. Open the attached solution [SourceGeneratorTest.zip](https://github.com/user-attachments/files/22911645/SourceGeneratorTest.zip)
2. Open `Program.cs` in the editor
3. Rebuild the solution

To reproduce again delete `bin` and `obj` folder from the `Generator` project folder before opening the solution.

**Expected Behavior**:
After rebuilding the project without errors, code analysis and the error list don't show any errors

**Actual Behavior**:
Roslyn shows the generator as not generating any files in solution explorer.
Roslyn shows errors caused by missing types provided by the source generator.

https://github.com/user-attachments/assets/fd9693e6-4913-47a7-973d-a60cd4350aaa

**Notes**:
- after a second build, or upon saving the file (even though there are no actual changes) Roslyn recognizes files from the source generator
- it also recognizes it if you first rebuild the solution and then navigate to `Program.cs`

I believe that it is similar to #80714 - Roslyn doesn't queue an update after reloading an assembly with the source generator, causing it to wait indefinitely for some next event (such as new build request) that would trigger it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.