microsoft-ui-xaml
microsoft-ui-xaml copied to clipboard
Closing multi-window app results in unhandled win32 exception.
Describe the bug
The application will often crash, without generating any dump. Event viewer will show an “access violation error 0xc0000005”
Steps to reproduce the bug
-
Create new MAUI app
-
Add a button in the MainPage.xaml and implement the Clicked event handler in the code behind.
// button - to open a new window private void Btn_Clicked(object sender, EventArgs e) { var page = new ContentPage() { Content = new Label() { Text = "" } }; var win = new Window() { Page = page };
App.Current.OpenWindow(win);
}
-
Run app targeting .net6.0-windows platform
-
Click on the button multiple times to open multiple windows (say 10 windows)
-
Start closing the windows and notice app crashes.
Expected behavior
All windows should close without app crashing.
Screenshots
No response
NuGet package version
No response
Windows app type
- [ ] UWP
- [X] Win32
Device form factor
Desktop
Windows version
Windows 11 (21H2): Build 22000
Additional context
No response
Likely the same underlying issue as #7564, but happening on window close rather than opening another.
@codendone Hey Mike, to add a little more context to this. We (CSS) were able to Repro this on WInUI3, but its not as consistent. On MAUI we can reproduce easily, very quickly. Please reach out if you have any questions or need us to demostrate.
This appears to be timing issue. We are attempting to raise a layout changed event using a handler that no longer exists. This might not normally be a problem since if the handler is missing we attempt to unregister it and move on. However, this assumes that the event is attached to the source passed when the event was raised. But we explicitly don't pass a source for LayoutUpdated, so this value is null when we try to detach the event handler and we crash. This probably has something to do garbage collection since I can't ever get it to fail on the first couple of windows. Only after opening and closing a few does the crash happen.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.