-
Notifications
You must be signed in to change notification settings - Fork 117
Description
Description
When I open a new child window in UWP (.NET 9) and try to close it using Window.Current.Close()
, the following exception is thrown:
System.InvalidOperationException
HResult=0x80131509
Message=Cannot release objects that are not runtime wrappers of native WinRT objects.
Source=WinRT.Runtime
StackTrace:
at WinRT.DefaultComWrappers.ReleaseObjects(IEnumerable objects) in WinRT\DefaultComWrappers.cs:line 145
This works without issues in UWP .Net Native.
However, closing the child window with ApplicationView.GetForCurrentView().TryConsolidateAsync()
seems to work better. That said, it still crashes in my production app if I place a breakpoint on that line, but works fine without the breakpoint. Interestingly, I could not reproduce this issue in the provided sample app.
I also observed that the crash occurs when building for Debug/x64, but it works correctly when building for Debug/x86.
Steps To Reproduce
- Open a new child window
async void OpenChildWindowButton_Click(object sender, RoutedEventArgs e)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(ChildPage), null);
Window.Current.Content = frame;
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
- Close the child window
async void CloseChildWindowButton_Click(object sender, RoutedEventArgs e)
{
// crash
Window.Current.Close();
// no crash
//await ApplicationView.GetForCurrentView().TryConsolidateAsync();
}
When testing make sure the build target Debug/x64 is selected.
Expected Behavior
No crash.
Version Info
VS 17.13.4
Additional Context
Sample app to reproduce the issue.
Metadata
Metadata
Assignees
Labels
No labels