Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Remove explicit WinRT initialization/uninitialization - #122940

#122940
Merged
jkotas merged 5 commits into
maindotnet/runtime:mainfrom
copilot/remove-explicit-winrt-initializationdotnet/runtime:copilot/remove-explicit-winrt-initializationCopy head branch name to clipboard
Jan 7, 2026
Merged

Remove explicit WinRT initialization/uninitialization#122940
jkotas merged 5 commits into
maindotnet/runtime:mainfrom
copilot/remove-explicit-winrt-initializationdotnet/runtime:copilot/remove-explicit-winrt-initializationCopy head branch name to clipboard

Conversation

Copilot AI commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Description

Removes redundant WinRT initialization code. Standard COM initialization via CoInitializeEx/CoUninitialize is sufficient for COM/WinRT interop.

Changes:

  • Removed TSNC_WinRTInitialized thread state flag and associated methods (IsWinRTInitialized, ResetWinRTInitialized, BaseWinRTUninitialize)
  • Removed all RoInitialize/RoUninitialize calls from CoreCLR thread apartment setup
  • Removed ENABLE_WINRT conditional compilation from NativeAOT - now always uses CoInitializeEx
  • Removed RuntimeObject.lib dependency from build configurations (no longer needed)
  • Simplified COM cleanup logic by removing redundant IsCoInitialized() checks in three locations

Files modified:

  • src/coreclr/vm/threads.{h,cpp} - Thread state and COM initialization cleanup
  • src/coreclr/nativeaot/.../Thread.NativeAot.Windows.cs - NativeAOT COM initialization
  • 5 CMakeLists.txt files - Removed RuntimeObject.lib linking

Customer 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

  • CoreCLR build validated on Linux x64 Release configuration
  • All build breaks fixed and verified on subsequent builds
  • Code simplifications verified through successful compilation

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

Create PR that deletes explicit WinRT initialization/uninitialization

  • TSNC_WinRTInitialized flag, IsWinRTInitialized and related methods
  • ENABLE_WINRT define and RoInitialize method
  • Check whether RuntimeObject.lib is still needed for linking

💡 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.

- 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 <6668460+jkotas@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove explicit WinRT initialization and related components Remove explicit WinRT initialization/uninitialization Jan 6, 2026
Copilot AI requested a review from jkotas January 6, 2026 21:51
@jkotas

jkotas commented Jan 6, 2026

Copy link
Copy Markdown
Member

@copilot FIx build break

D:\a_work\1\s\src\coreclr\vm\threads.cpp(3724): error C3861: 'IsWinRTInitialized': identifier not found

Comment thread src/coreclr/vm/threads.cpp Outdated
Comment thread src/coreclr/vm/threads.h Outdated
jkotas and others added 2 commits January 6, 2026 14:13
Removed the remaining reference to IsWinRTInitialized() at line 3724 in threads.cpp that was causing the build break.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

Copilot AI commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

@copilot FIx build break

D:\a_work\1\s\src\coreclr\vm\threads.cpp(3724): error C3861: 'IsWinRTInitialized': identifier not found

Fixed in 93a16eb. Removed the missed IsWinRTInitialized() reference at line 3724 in threads.cpp.

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 <6668460+jkotas@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

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 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_WinRTInitialized thread state flag and all WinRT-specific initialization/cleanup methods from CoreCLR
  • Eliminated ENABLE_WINRT conditional compilation from NativeAOT, standardizing on CoInitializeEx
  • Removed RuntimeObject.lib dependency 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

@jkoritzinsky jkoritzinsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@jkotas

jkotas commented Jan 7, 2026

Copy link
Copy Markdown
Member

/ba-g DeadLetter

@jkotas
jkotas merged commit 8d5d39a into main Jan 7, 2026
211 of 216 checks passed
@jkotas
jkotas deleted the copilot/remove-explicit-winrt-initialization branch January 7, 2026 03:51
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.