V14: Add JsonDocumentOptions skipping comments in appsettings #16281
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.
We'll explode if you try to install while there are comments in the
appsettings.json
To fix this I've added some
JsonDocumentOptions
to skip comments, unfortunately, this means that any comments will be removed, because they're not read in when manipulating the JSON.The reason for this is that since .NET Core 3.1 the
JsonDocument
andJsonSerializer
do not support allowing comments, you'll just get an error if you try.The underlying reason is that the JSON spec does not support comments, and the dotnet team seems to feel very strongly about adhering to the spec, which is fair enough but means we cannot support having the comments in the app settings JSON document. For more information see the following discussion dotnet/runtime#35251 (Warning: It's a very heated debate).
Testing
Try installing while there is a comment in the
appsettings.json
it should no longer explode, but the comment will disappear.