launchSettings.json no longer allows comments after System.Text.Json migration
See original GitHub issueAs 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
dotnet new web
- Edit
.\Properties\launchSettings.json
to include a comment:// Spicy Comments
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
Issue Analytics
- State:
- Created 4 years ago
- Comments:23 (15 by maintainers)
Top Results From Across the Web
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Json accept them, see Allow comments and trailing commas. There's no way to allow multiple trailing commas. Converter registration precedence.
Read more >Use multiple environments in ASP.NET Core
Provides an IWebHostEnvironment instance in the Environment property ... The following JSON shows the launchSettings.json file for an ASP.
Read more >How can I parse JSON with comments using System.Text. ...
JSON containing comments can be parsed by System.Text.Json , but by default such JSON is considered invalid, likely since comments are not ...
Read more >Is there a way to change/override settings in ...
appsettings.json can be overridden just for me with an ignored appsettings.Development.json, but I can't find any analogue for launchSettings.
Read more >Should you use Newtonsoft.Json or System.Text. ...
My understanding is that he did not work on System.Text.Json. He is at Microsoft but doing other things. I see this often repeated...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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.