Skip to content

Allow comments and trailing commas in launchSettings.json profile parsing - #54820

Merged
Evangelink merged 1 commit into
dotnet:mainfrom
Evangelink:dev/evangelink/fix-launchsettings-comments-54155
Jun 17, 2026
Merged

Allow comments and trailing commas in launchSettings.json profile parsing#54820
Evangelink merged 1 commit into
dotnet:mainfrom
Evangelink:dev/evangelink/fix-launchsettings-comments-54155

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #54155 (and unblocks microsoft/testfx#7952).

Problem

dotnet run fails to read a launchSettings.json that contains JSON comments or trailing commas:

The launch profile "(Default)" could not be applied.
An error was encountered when reading '...launchSettings.json': '/' is invalid after a value. ...

Root cause

LaunchSettings.ReadProfileSettingsFromFile parses the whole file with a JsonDocument configured with JsonCommentHandling.Skip / AllowTrailingCommas = true, then hands the selected profile's raw text (JsonElement.GetRawText(), which still contains any comments) to the source-generated ProjectLaunchProfileParser / ExecutableLaunchProfileParser. Those deserializers used LaunchProfileJsonSerializerContext with 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)] to LaunchProfileJsonSerializerContext, matching the top-level JsonDocument options and the dotnet-watch launch settings reader.

Tests

Added regression tests CommentsAndTrailingCommas_Executable / CommentsAndTrailingCommas_Project to LaunchSettingsParserTests. All LaunchSettingsParserTests pass locally.

…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LaunchProfileJsonSerializerContext source-generated deserialization to Skip comments and AllowTrailingCommas.
  • 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

@Youssef1313

Copy link
Copy Markdown
Member

Please consider fixing for release/10.0.3xx.

@Evangelink
Evangelink merged commit 920580c into dotnet:main Jun 17, 2026
26 checks passed
@Evangelink
Evangelink deleted the dev/evangelink/fix-launchsettings-comments-54155 branch June 22, 2026 16:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comment/Trailing comma handling in launchSettings.json is not uniform.

4 participants