fix: guard OSArchitecture access against PropertyNotFoundException under strict mode - #54684
Merged
nagilson merged 8 commits intoJun 25, 2026
Merged
Conversation
…NotFoundException Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix intermittent 'OSArchitecture' PropertyNotFoundException in get-dotnetup.ps1
fix: guard OSArchitecture access against PropertyNotFoundException under strict mode
Jun 10, 2026
nagilson
reviewed
Jun 10, 2026
nagilson
marked this pull request as ready for review
June 15, 2026 22:59
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens get-dotnetup.ps1 runtime architecture detection to avoid PropertyNotFoundException from [RuntimeInformation]::OSArchitecture when running under Windows PowerShell 5.1 with Set-StrictMode -Version Latest, preventing bootstrap failures on older .NET Framework environments.
Changes:
- Wraps
RuntimeInformation::OSArchitectureaccess intry/catchand falls back when it fails. - Adds fallback architecture detection via
$env:PROCESSOR_ARCHITECTUREon Windows anduname -mon Linux/macOS.
Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Member
|
@nagilson Is this still valid? Was it fixed when flowing the scripts to main or elsewhere? |
Member
|
It's not fixed yet, I'm waiting for #54756 to merge now and maybe merge with main again after that. I need to clean up the AI code. |
… not reliable with polyfill
The fallback is windows only because linux and darwin should run on powershell core which wont let the runtime information throw.
Member
nagilson
approved these changes
Jun 24, 2026
baronfel
approved these changes
Jun 25, 2026
Member
|
the failing test is flakey and this def did not cause a nuget breaking change |
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.

On Windows PowerShell 5.1 with older .NET Framework,
[System.Runtime.InteropServices.RuntimeInformation]::OSArchitecturecan throwPropertyNotFoundExceptionunderSet-StrictMode -Version Latest, intermittently blocking SDK bootstrap.Changes
scripts/get-dotnetup.ps1: WrapRuntimeInformation::OSArchitectureaccess in a standalone helper patterned after the SDK toolset scripts' existing native-architecture helper. On failure, the helper falls back to the same default behavior used by those scripts.This keeps
get-dotnetup.ps1standalone while aligning its architecture detection behavior with the existing SDK toolset helpers.It also adds a test to keep the two implementations in sync since
maincannot have thescriptand the script must work standalone.