Hide HasUnwrappableNativeObjectReference and IsOverridableInterface from reference projections#2371
Merged
Sergio0694 merged 2 commits intostaging/3.0from Mar 27, 2026
Conversation
…rom reference projections Change both members from abstract to virtual on WindowsRuntimeObject, with default implementations that throw UnreachableException. Add a new UnreachableException.Throw() helper in WindowsRuntimeExceptionExtensions. Update cswinrt.exe to skip generating these overrides entirely when producing reference projections. Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
The type is no longer referenced by the code generator after the previous change that removed the Obsolete/EditorBrowsable attributes from generated reference projection overrides. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
manodasanW
approved these changes
Mar 27, 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 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.
Summary
Hide
HasUnwrappableNativeObjectReferenceandIsOverridableInterfacefrom reference projections by making them virtual (instead of abstract) onWindowsRuntimeObjectand skipping their codegen incswinrt.exefor reference projection mode.Motivation
These two members are private implementation details that only matter at app build time (when the actual projection implementations are generated). Reference projections don't need them — they exist solely to satisfy the abstract contract. By making the base class members virtual with an
UnreachableExceptiondefault, reference projections no longer need to emit dummy overrides, keeping their API surface cleaner and avoiding unnecessary code in distributed NuGet packages.Changes
src/WinRT.Runtime2/WindowsRuntimeObject.cs: ChangeHasUnwrappableNativeObjectReferenceandIsOverridableInterfacefromabstracttovirtual, with default implementations that throwUnreachableExceptionsrc/WinRT.Runtime2/Properties/WindowsRuntimeExceptionExtensions.cs: AddUnreachableException.Throw()helper following the existing extension patternsrc/cswinrt/code_writers.h: Skip generatingHasUnwrappableNativeObjectReferenceandIsOverridableInterfaceoverrides whensettings.reference_projectionis true