-
Notifications
You must be signed in to change notification settings - Fork 10.5k
backport(9.0): Fix runtime architecture detection logic in ANCM. #63707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
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 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
ProcessorArchitecture
enum 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"); |
Copilot
AI
Sep 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
static_assert(false, "Unknown target architecture"); | |
static_assert(sizeof(void*) == 0, "Unknown target architecture"); |
Copilot uses AI. Check for mistakes.
Please send the usual mail to tactics. |
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.exe
outputs trying to find dotnet binary. It takes OS / process / dotnet arch installed combination to affect the behavior.Verification
Packaging changes reviewed?