Skip to content

Add 'EnableComWrappersReleaseObjects' feature switch#2343

Closed
Sergio0694 wants to merge 3 commits intomasterfrom
dev/enable-comwrappers-release-objects-switch
Closed

Add 'EnableComWrappersReleaseObjects' feature switch#2343
Sergio0694 wants to merge 3 commits intomasterfrom
dev/enable-comwrappers-release-objects-switch

Conversation

@Sergio0694
Copy link
Member

This PR adds a new EnableComWrappersReleaseObjects feature switch (enabled by default) that controls whether DefaultComWrappers.ReleaseObjects disposes objects or not.

Motivation

In some specific scenarios where a long-lived app uses multiple windows, previously instantiated XAML objects can be marked as disposed when the runtime calls ReleaseObjects. This feature switch allows disabling that behavior so those objects remain accessible.

Changes

  • FeatureSwitches.cs: added EnableComWrappersReleaseObjects property with its constant name (CSWINRT_ENABLE_COMWRAPPERS_RELEASE_OBJECTS) and backing field, following the existing pattern.
  • ILLink.Substitutions.xml: added substitution entries for the new switch to support IL trimming.
  • Microsoft.Windows.CsWinRT.targets: added CsWinRTEnableComWrappersReleaseObjects MSBuild property (default: true) and the corresponding RuntimeHostConfigurationOption for trimming.
  • ComWrappersSupport.net5.cs: added an early return guard in DefaultComWrappers.ReleaseObjects when the switch is disabled.

Sergio0694 and others added 3 commits March 17, 2026 12:50
Add a new 'EnableComWrappersReleaseObjects' feature switch (enabled by default)
to FeatureSwitches.cs with its backing field and property name constant, and add
the corresponding ILLink substitution entries for trimming support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add 'CsWinRTEnableComWrappersReleaseObjects' MSBuild property (default: true)
and the corresponding 'CSWINRT_ENABLE_COMWRAPPERS_RELEASE_OBJECTS' runtime host
configuration option for IL trimming support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Objects

Skip releasing objects when the feature switch is disabled, allowing long-lived
apps with multiple windows to retain access to previously instantiated XAML
objects that would otherwise be marked as disposed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Sergio0694 Sergio0694 closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant