Roslyn locks and doesn't unlock AnalyzerReference files after calling `GetCompilationAsync`
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: 4.13.0 (net8.0)
**Steps to Reproduce**:
1. Run `SimpleApp` project from example via `dotnet run` (just for restore and build)
2. Run `RoslynApp` project from example via `dotnet run`
3. You can see that SourceGen assembly has been loaded into AppDomain:
```
Assembly: SourceGen, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
```
4. This file is locked on Windows now:

dotnet build also doesn't work.
Example: https://github.com/JaneySprings/RoslynLockIssue
**Expected Behavior**:
SourceGen.dll is not locked
**Actual Behavior**:
SourceGen.dll is locked
Contributor guide
Research direction
Start with the linked RoslynLockIssue example and run SimpleApp with dotnet run, followed by RoslynApp with dotnet run, to reproduce the Windows file lock. Trace the GetCompilationAsync call and AnalyzerReference handling from that reproduction. Done means SourceGen.dll is no longer locked and dotnet build works afterward.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100