Remove explicit WinRT initialization/uninitialization#122940
Merged
Conversation
- Remove TSNC_WinRTInitialized flag from threads.h - Remove IsWinRTInitialized() and ResetWinRTInitialized() methods - Remove BaseWinRTUninitialize() method declaration and implementation - Remove all RoInitialize/RoUninitialize calls from CoreCLR - Remove ENABLE_WINRT conditional compilation from NativeAOT - Remove RuntimeObject.lib from all CMakeLists.txt files Co-authored-by: jkotas <[email protected]>
Copilot
AI
changed the title
[WIP] Remove explicit WinRT initialization and related components
Remove explicit WinRT initialization/uninitialization
Jan 6, 2026
Member
|
@copilot FIx build break D:\a_work\1\s\src\coreclr\vm\threads.cpp(3724): error C3861: 'IsWinRTInitialized': identifier not found |
jkotas
reviewed
Jan 6, 2026
jkotas
reviewed
Jan 6, 2026
Removed the remaining reference to IsWinRTInitialized() at line 3724 in threads.cpp that was causing the build break. Co-authored-by: jkotas <[email protected]>
Contributor
Author
Removed redundant IsCoInitialized() checks that were performed both before and inside the conditional blocks. Applied the same simplification in three locations in threads.cpp as requested in code review. Co-authored-by: jkotas <[email protected]>
jkotas
approved these changes
Jan 6, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes redundant WinRT-specific initialization code from the runtime, consolidating all COM/WinRT interop to use standard COM initialization via CoInitializeEx/CoUninitialize.
Key Changes:
- Removed
TSNC_WinRTInitializedthread state flag and all WinRT-specific initialization/cleanup methods from CoreCLR - Eliminated
ENABLE_WINRTconditional compilation from NativeAOT, standardizing onCoInitializeEx - Removed
RuntimeObject.libdependency from all build configurations
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/threads.h | Removed TSNC_WinRTInitialized flag and WinRT-specific methods (IsWinRTInitialized, ResetWinRTInitialized, BaseWinRTUninitialize) |
| src/coreclr/vm/threads.cpp | Removed BaseWinRTUninitialize() implementation and all RoInitialize/RoUninitialize calls; simplified COM cleanup logic by removing redundant checks in CoUninitialize(), CleanupCOMState(), and SetApartment() |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Windows.cs | Removed ENABLE_WINRT conditionals, now always using CoInitializeEx/CoUninitialize instead of RoInitialize/RoUninitialize |
| src/native/corehost/apphost/static/CMakeLists.txt | Removed RuntimeObject.lib linking dependency |
| src/coreclr/jit/CMakeLists.txt | Removed RuntimeObject.lib linking dependency |
| src/coreclr/ildasm/exe/CMakeLists.txt | Removed RuntimeObject.lib linking dependency |
| src/coreclr/ilasm/CMakeLists.txt | Removed RuntimeObject.lib linking dependency |
| src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt | Removed RuntimeObject.lib linking dependency |
AaronRobinsonMSFT
approved these changes
Jan 7, 2026
Member
|
/ba-g DeadLetter |
This was referenced Jan 9, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Removes redundant WinRT initialization code. Standard COM initialization via
CoInitializeEx/CoUninitializeis sufficient for COM/WinRT interop.Changes:
TSNC_WinRTInitializedthread state flag and associated methods (IsWinRTInitialized,ResetWinRTInitialized,BaseWinRTUninitialize)RoInitialize/RoUninitializecalls from CoreCLR thread apartment setupENABLE_WINRTconditional compilation from NativeAOT - now always usesCoInitializeExRuntimeObject.libdependency from build configurations (no longer needed)IsCoInitialized()checks in three locationsFiles modified:
src/coreclr/vm/threads.{h,cpp}- Thread state and COM initialization cleanupsrc/coreclr/nativeaot/.../Thread.NativeAot.Windows.cs- NativeAOT COM initializationCustomer Impact
None. This is internal runtime cleanup with no customer-facing behavior changes. COM/WinRT interop continues to work through standard COM infrastructure.
Regression
No. This removes code, does not change existing behavior.
Testing
Risk
Low. Changes are deletions of redundant initialization code and simplification of conditional logic. COM initialization remains intact via
CoInitializeEx, which already handles COM/WinRT threading requirements.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.