V14: Add JsonDocumentOptions skipping comments in appsettings#16281
Merged
V14: Add JsonDocumentOptions skipping comments in appsettings#16281
Conversation
Member
|
LGTM 🚀 |
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.
We'll explode if you try to install while there are comments in the
appsettings.jsonTo fix this I've added some
JsonDocumentOptionsto 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
JsonDocumentandJsonSerializerdo 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.jsonit should no longer explode, but the comment will disappear.