Repository navigation
[release/11.0.2xx] Fix dotnet watch crash after switching target frameworks - #57088
Draft
jonathanpeppers wants to merge 2 commits into
Draft
jonathanpeppers wants to merge 2 commits into
jonathanpeppers wants to merge 2 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The filter incorrectly excludes F# and VB projects without CscCommandLineArgs, removing workspace documents needed to trigger rebuilds or restarts and potentially leaving apps running stale code after source edits.
1 open issue
What changed in this PR
This PR addresses a dotnet watch Hot Reload crash after switching target frameworks by filtering the project instances loaded into Roslyn based on available compiler inputs.
Changes:
- Excludes project instances without C# compiler arguments from the workspace.
- Adds regression coverage for edits with and without a previously built inactive target.
- Updates reference-project coverage to include a different target framework and design-time evaluation.
| File | Description |
|---|---|
test/dotnet-watch.Tests/HotReload/CompilationHandlerTests.cs |
Adds cross-target regression cases and updates reference-project setup. |
src/Dotnet.Watch/Watch/HotReload/ManagedCodeWorkspace.cs |
Filters workspace project instances by compiler-argument availability. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 12, 2026
Member
Author
|
This might be fixed by: I think we should let the fix flow to VMR and see if the test added here passes. |
jonathanpeppers
marked this pull request as draft
November 13, 2026 15:58
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

A MAUI project can target both Windows and Android. Running it on Windows, then Android, then starting
dotnet watchfor Android can make the first C# edit crash with aNullReferenceExceptionin Roslyn'sDefinitionMap.GetPreviousMethodHandle.Watch prepares compiler inputs for the selected target, but also loaded the other targets into Roslyn. If the earlier Windows build still matched the source, Roslyn tried to update Windows without complete compiler inputs, even though only Android was running.
This change passes the project instances from completed design-time builds to Roslyn, instead of every target in the project graph. It does not depend on C# compiler items, so VB and F# projects are kept too. Referenced projects targeting other frameworks are still included.
The regression test reproduces the crash without MAUI or a device: build another target first, start watch for the selected target, then edit a method. The control case skips the earlier build. All 18 focused tests pass, including source edits in VB and F#, dependencies, and project changes.
Related to dotnet/roslyn#79898. This fixes the reproduced cross-target case; I have not confirmed whether it also fixes the empty-update case in that issue.
Full stack trace from the MAUI reproduction