Clarify Encoding.GetEncoding(0) and Encoding.Default behavior differences between .NET Framework and .NET Core+ #11712
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.
This PR clarifies the documentation for
Encoding.GetEncoding(0)
andEncoding.Default
to explain their different behaviors between .NET Framework and .NET Core/later versions.Background
In .NET Framework, both
Encoding.Default
andEncoding.GetEncoding(0)
return the system's active code page encoding. However, in .NET Core and later versions, this behavior changed:Encoding.Default
always returns UTF-8Encoding.GetEncoding(0)
behavior depends on registered encoding providersThis difference can cause confusion for developers migrating code between frameworks.
Changes Made
Enhanced
Encoding.Default
DocumentationAdded comprehensive remarks explaining that:
GetEncoding(0)
)Clarified
Encoding.GetEncoding(int)
Behavior forcodepage = 0
Updated documentation to explain platform and provider-specific behavior:
Encoding.Default
)CodePagesEncodingProvider
registered: Windows returns active code page, non-Windows returns UTF-8Updated
Encoding.RegisterProvider
DocumentationEnhanced explanation of how registering encoding providers affects
GetEncoding(0)
behavior, with specific details aboutCodePagesEncodingProvider
's platform-specific impact.Improved
CodePagesEncodingProvider
DocumentationGetEncoding(int)
method documentation with specificcodepage = 0
behaviorThese changes help developers understand the encoding behavior differences and make informed decisions when writing cross-platform code.
Fixes #11711.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.