Allow comments and trailing commas in launchSettings.json profile parsing - #54820
Merged
Evangelink merged 1 commit intoJun 17, 2026
Conversation
…sing The dotnet run launch settings reader parses the whole file with a JsonDocument that skips comments, but then passes the profile's raw text (which still contains the comments) to source-generated deserializers that had no comment/trailing-comma handling configured, causing 'invalid after a value' JsonException for files with comments. Add JsonSourceGenerationOptions(ReadCommentHandling = Skip, AllowTrailingCommas = true) to LaunchProfileJsonSerializerContext so the Project/Executable profile parsers tolerate comments and trailing commas, matching the top-level JsonDocument options and the dotnet-watch reader. Fixes dotnet#54155 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in dotnet run launch profile parsing where launchSettings.json profiles containing JSON comments or trailing commas could not be deserialized by the source-generated parsers, despite the top-level JsonDocument already allowing those features.
Changes:
- Configure
LaunchProfileJsonSerializerContextsource-generated deserialization toSkipcomments andAllowTrailingCommas. - Add regression tests covering comments + trailing commas for both Executable and Project launch profiles.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/ProjectTools/LaunchSettingsParserTests.cs | Adds regression tests that ensure profile parsing succeeds with comments and trailing commas. |
| src/Microsoft.DotNet.ProjectTools/LaunchSettings/LaunchProfileJsonSerializerContext.cs | Adds JsonSourceGenerationOptions to align generated deserializers with the permissive top-level JSON parsing behavior. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 0
Evangelink
enabled auto-merge (squash)
June 17, 2026 12:58
nohwnd
approved these changes
Jun 17, 2026
Member
|
Please consider fixing for release/10.0.3xx. |
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.
Fixes #54155 (and unblocks microsoft/testfx#7952).
Problem
dotnet runfails to read alaunchSettings.jsonthat contains JSON comments or trailing commas:Root cause
LaunchSettings.ReadProfileSettingsFromFileparses the whole file with aJsonDocumentconfigured withJsonCommentHandling.Skip/AllowTrailingCommas = true, then hands the selected profile's raw text (JsonElement.GetRawText(), which still contains any comments) to the source-generatedProjectLaunchProfileParser/ExecutableLaunchProfileParser. Those deserializers usedLaunchProfileJsonSerializerContextwith no comment/trailing-comma handling, so they throw.This is a regression introduced when profile parsing moved to source-generated deserialization.
Fix
Add
[JsonSourceGenerationOptions(ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true)]toLaunchProfileJsonSerializerContext, matching the top-levelJsonDocumentoptions and thedotnet-watchlaunch settings reader.Tests
Added regression tests
CommentsAndTrailingCommas_Executable/CommentsAndTrailingCommas_ProjecttoLaunchSettingsParserTests. AllLaunchSettingsParserTestspass locally.