sdk: launchSettings.json no longer allows comments after System.Text.Json migration

As part of the migration to System.Text.Json, it looks like Comment handling in launchSettings.json was lost. This issue does not repro on SDK 2.2.203.

System.Text.Json supports comment handling, but it has to be enabled in the options. It looks like the current code does not pass in any options: https://github.com/dotnet/cli/blob/0cb36481ad4e628079374447c8ae313006e3f602/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs#L28

Steps to reproduce

  1. dotnet new web
  2. Edit .\Properties\launchSettings.json to include a comment: // Spicy Comments
  3. dotnet run

Expected behavior

It runs, spicy comments and all. Any launch settings (environment variables, etc.) are applied.

Actual behavior

The launch profile "(Default)" could not be applied.
An error was encountered when reading launchSettings.json.
'/' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: 1 | BytePositionInLine: 2

The application does launch, but launch settings are ignored.

😢

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.203
 Commit:    e5bab63eca

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18865
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.203\

Host (useful for support):
  Version: 3.0.0-preview6-27804-01
  Commit:  fdf81c6faf

.NET Core SDKs installed:
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.603 [C:\Program Files\dotnet\sdk]
  2.1.700-preview-009601 [C:\Program Files\dotnet\sdk]
  2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
  2.2.203 [C:\Program Files\dotnet\sdk]
  3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (15 by maintainers)

Most upvoted comments

I have encountered the same issue, and after some investigation, I simply edited the launchSettings.json file and saved it again

Comments should be allowed in any config file that a user can edit. Strictness in trailing commas is a nuisance but not the same as forbidding comments in user hostility.

Also feels like I should be allowed to add comments to tools manifest even if it hasn’t ever sbipped rtm with comment support. Will, I’m sorry to be changing my mind here and also sorry that I don’t remember the discussion you mention. It’s like a one line change to opt in to comments, right? So far I haven’t heard any real reason not to do that. Just reasons why it’s not likely to be a breaking change.

Just a data point to add to the .runtimeconfig.json discussion: The native core-host logic does permit comments in .runtimeconfig.json (I just tested it 😃).

If there are places where the SDK is reading JSON files, it seems appropriate to make them as compatible with the old logic as possible (for the places we know we can support) to encourage users to move to the latest SDK without reservation. Obviously there will be unintentional breaks and things that can’t be aligned, but I don’t see why we should arbitrarily block things we know are currently allowed and can be allowed in the new parser.

It is also definitely a valid customer scenario to edit the .runtimeconfig.json file. I was just talking to a customer who was doing so 😃. Having said that, they are usually edited after deployment so the SDK’s behavior doesn’t matter as much there.

The launchSettings.json file is more critical though, as it is a clear customer scenario, so I’m relatively unenthusiastic about .runtimeconfig.json. I just don’t want the line we draw to be arbitrary.

For further reference, the native host does not permit trailing commas in the .runtimeconfig.json file 😄.

@nguerrera I wonder if the SDK had other files that supported comments previously but don’t with the new JSON library: https://github.com/dotnet/cli/search?q=JsonDocument.Parse&unscoped_q=JsonDocument.Parse&type=Code https://github.com/dotnet/cli/search?q=JsonSerializer.Deserialize&unscoped_q=JsonSerializer.Deserialize&type=Code

It might be worthwhile doing a review.