backport(9.0): Fix runtime architecture detection logic in ANCM.#63707
Merged
joperezr merged 1 commit intorelease/9.0from Sep 19, 2025
Merged
backport(9.0): Fix runtime architecture detection logic in ANCM.#63707joperezr merged 1 commit intorelease/9.0from
joperezr merged 1 commit intorelease/9.0from
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR backports a fix for runtime architecture detection logic in the ASP.NET Core Module (ANCM) to .NET 9.0. The changes replace the previous boolean-based x64 detection with a more comprehensive processor architecture system that supports x86, AMD64, and ARM64 architectures.
- Introduces a new
ProcessorArchitectureenum to handle multiple architecture types instead of just x64/x86 - Replaces runtime PE header magic number detection with compile-time architecture detection
- Updates architecture matching logic to use the new enum-based system for finding compatible dotnet.exe instances
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ProcessorArchitecture.h | New header defining ProcessorArchitecture enum and string conversion utility |
| HostFxrResolver.h | Updates method signature from IsX64 to GetFileProcessorArchitecture |
| HostFxrResolver.cpp | Refactors architecture detection logic and improves PE header parsing |
| Environment.h | Adds GetCurrentProcessArchitecture method declaration |
| Environment.cpp | Implements compile-time architecture detection using preprocessor macros |
| #elif defined(_M_IX86) | ||
| return ProcessorArchitecture::x86; | ||
| #else | ||
| static_assert(false, "Unknown target architecture"); |
There was a problem hiding this comment.
Use static_assert(false) with a dependent type to avoid immediate compilation failure. Consider using static_assert(sizeof(void*) == 0, ...) or a template-dependent expression to ensure this only triggers when the code path is actually instantiated.
Suggested change
| static_assert(false, "Unknown target architecture"); | |
| static_assert(sizeof(void*) == 0, "Unknown target architecture"); |
Member
|
Please send the usual mail to tactics. |
danmoseley
approved these changes
Sep 17, 2025
This was referenced Oct 14, 2025
Closed
This was referenced Mar 27, 2026
Open
Open
This was referenced Apr 3, 2026
Open
Open
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.
Description
Backport of #63652 to net9.0
A change (#61894) improved algorithm to determine the architecture of a binary by switching away from
GetBinaryTypeW(which seems to load the exe into executable space which might trigger custom windows policies). It was backported to net9.0: #62038.However, we spotted that sometimes function incorrectly chooses a binary of an incompatible architecture, resulting in crashing site load.
Current change specifically checks for a full compatibility of bitness and architecture.
Fixes #63650
Customer Impact
For example users hosting x86 app on x64 machine / x64 app on arm64 machine are impacted unless current change is merged and used.
Regression?
Risk
Impacts users who are using different process architecture then what
where.exeoutputs trying to find dotnet binary. It takes OS / process / dotnet arch installed combination to affect the behavior.Verification
Packaging changes reviewed?