Support UTF-16 BOM in global.json - #53141
#53141Merged
nagilson merged 5 commits intoMar 11, 2026
maindotnet/sdk:mainfrom
copilot/support-utf16-bom-global-jsondotnet/sdk:copilot/support-utf16-bom-global-jsonCopy head branch name to clipboard
Merged
Support UTF-16 BOM in global.json#53141nagilson merged 5 commits intomaindotnet/sdk:mainfrom copilot/support-utf16-bom-global-jsondotnet/sdk:copilot/support-utf16-bom-global-jsonCopy head branch name to clipboard
nagilson merged 5 commits into
maindotnet/sdk:mainfrom
copilot/support-utf16-bom-global-jsondotnet/sdk:copilot/support-utf16-bom-global-jsonCopy head branch name to clipboard
Conversation
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Support UTF-16 BOM for global.json handling
Support UTF-16 BOM in global.json
Feb 24, 2026
baronfel
reviewed
Feb 25, 2026
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
baronfel
reviewed
Feb 25, 2026
…nual BOM probing Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
baronfel
approved these changes
Feb 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the workload manifest reader’s global.json parsing to correctly handle user-authored global.json files encoded with UTF-16 (with BOM), which previously could silently fail due to assuming UTF-8 bytes.
Changes:
- Detects file encoding via
StreamReaderBOM detection and selects an efficient parsing path (direct stream for UTF-8; in-memory transcode for non-UTF-8). - Extracts the JSON-walking logic into a shared
ParseGlobalJsonhelper to avoid duplication. - Adds a theory test covering UTF-16 LE and UTF-16 BE
global.jsonencodings.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.cs | Adds BOM-based encoding detection and UTF-16-compatible parsing while keeping the UTF-8 fast path. |
| test/Microsoft.NET.Sdk.WorkloadManifestReader.Tests/SdkDirectoryWorkloadManifestProviderTests.cs | Adds test coverage for UTF-16 LE/BE encoded global.json selecting workload sets correctly. |
nagilson
approved these changes
Feb 25, 2026
MiYanni
approved these changes
Feb 25, 2026
nagilson
enabled auto-merge
March 11, 2026 18:13
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.
global.jsonis user-authored and can be written with UTF-16 encoding (e.g., PowerShell'sOut-Filedefaults to UTF-16 on Windows). TheGlobalJsonReaderwas usingFile.OpenRead()feeding raw bytes intoUtf8JsonStreamReader, which only strips the UTF-8 BOM — silently failing on UTF-16 encoded files.Changes
SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.cs: Opens the file withStreamReader(detectEncodingFromByteOrderMarks: true), callsPeek()to trigger BOM detection, then checksCurrentEncodingto select the appropriate read path:BaseStreamback to position 0 and streams directly intoUtf8JsonStreamReader— no memory allocation.Utf8JsonStreamReaderhandles the UTF-8 BOM itself.StreamReader.ReadToEnd()to transcode the content to a UTF-8MemoryStream, which is then passed toUtf8JsonStreamReader. This is acceptable given how smallglobal.jsonfiles are.The JSON parsing logic was extracted into a
ParseGlobalJsonhelper to avoid duplicating the ~50 lines of JSON walking code across both paths.SdkDirectoryWorkloadManifestProviderTests.cs: AddedItUsesWorkloadSetFromGlobalJsonWithUtf16Encodingas a parameterized theory covering both UTF-16 LE and UTF-16 BE.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.