dotnet / dotnet/roslyn

Roslyn locks and doesn't unlock AnalyzerReference files after calling `GetCompilationAsync`

Open
#78,196 15 comments 0 reactions 0 assignees View on GitHub
Area-Analyzers IDE-MSBuildWorkspace untriaged
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:
![Image](https://github.com/user-attachments/assets/ae517b59-d147-4364-b142-6512c446b9d0)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.