Skip to content

fix: guard OSArchitecture access against PropertyNotFoundException under strict mode - #54684

Merged
nagilson merged 8 commits into
release/dnupfrom
copilot/fix-osarchitecture-propertynotfound
Jun 25, 2026
Merged

nagilson merged 8 commits into
release/dnupfrom
copilot/fix-osarchitecture-propertynotfound

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

On Windows PowerShell 5.1 with older .NET Framework, [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture can throw PropertyNotFoundException under Set-StrictMode -Version Latest, intermittently blocking SDK bootstrap.

Changes

  • scripts/get-dotnetup.ps1: Wrap RuntimeInformation::OSArchitecture access 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.ps1 standalone 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 main cannot have the script and the script must work standalone.

…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
Copilot AI requested a review from nagilson June 10, 2026 17:26
Comment thread scripts/get-dotnetup.ps1 Outdated
@nagilson
nagilson marked this pull request as ready for review June 15, 2026 22:59
Copilot AI review requested due to automatic review settings June 15, 2026 22:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::OSArchitecture access in try/catch and falls back when it fails.
  • Adds fallback architecture detection via $env:PROCESSOR_ARCHITECTURE on Windows and uname -m on Linux/macOS.

Comment thread scripts/get-dotnetup.ps1 Outdated
Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot AI requested a review from nagilson June 15, 2026 23:49
@dsplaisted

Copy link
Copy Markdown
Member

@nagilson Is this still valid? Was it fixed when flowing the scripts to main or elsewhere?

@nagilson

Copy link
Copy Markdown
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.

nagilson and others added 3 commits June 24, 2026 10:15
The fallback is windows only because linux and darwin should run on powershell core which wont let the runtime information throw.
@nagilson

Copy link
Copy Markdown
Member

A great test for this is to use sandbox, because that defaults to Windows Powershell with a framework version that fails to load the Runtime Architecture APIs.

I was able to confirm that the script now works properly.

image

@nagilson
nagilson requested a review from a team June 24, 2026 21:08
@nagilson
nagilson requested a review from a team June 25, 2026 18:11
@nagilson
nagilson merged commit 72b9324 into release/dnup Jun 25, 2026
27 of 30 checks passed
@nagilson
nagilson deleted the copilot/fix-osarchitecture-propertynotfound branch June 25, 2026 23:17
@nagilson

Copy link
Copy Markdown
Member

the failing test is flakey and this def did not cause a nuget breaking change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get-dotnetup.ps1: intermittent 'OSArchitecture' PropertyNotFoundException under strict mode

5 participants