WindowsAppSDK
WindowsAppSDK copied to clipboard
Blank WinUI 3 app crashes during closing
Describe the bug
WinUI 3 desktop C# apps throw a Win32 exception while closing (which by default VS is set to ignore that specific exception type). The exception...
Exception thrown at 0x76E5B502 (KernelBase.dll) in App.exe: WinRT originate error - 0x80000013 : 'The given object has already been closed / disposed and may no longer be used.'.
Steps to reproduce the bug
- Create a Blank App, Packaged C# (WinUI3 in Desktop).
- In VS, go to Debug -> Windows -> Exception Settings and then fully check the Win32 Exceptions box.
- Run the app and close it.
Expected behavior
App will terminate without any exception.
Screenshots

NuGet package version
1.0.0
Packaging type
Packaged (MSIX)
Windows version
May 2021 Update (19043)
IDE
Visual Studio 2022
Additional context
No response
Hi @dajbych, are you creating a C++ or C# app?
Hello @andrewleader, C# app.
@MikeHillberg @DrusTheAxe @BenJKuhn do any of you have any ideas who might own investigating this? Could be coming from WinUI 3 or coming from other code in the WinAppSDK, but something seems to be causing an exception upon app shutdown. I confirmed I can reproduce seeing the Win32 exception by enabling all Win32 exceptions in my debugger too.
@jeffstall, this is happening in DesktopChildSiteBridge::Close.
this is something I filed back in 2020; I think this one is a continuable/ignorable exception. We should not throw in the first place, but this is benign.
I don't need to adjust exception settings to see this error (multiple times).
Still see this exception when closing the window during debug.
Exception thrown at 0x00007FFCC402CD29 (KernelBase.dll) in MainUI.exe: WinRT originate error - 0x80000013 : 'The given object has already been closed / disposed and may no longer be used.'.
Is there any plan to fix this in the future?
also this:
onecoreuap\windows\frameworkudk\dxprivatescommon.cpp(53)\Microsoft.Internal.FrameworkUdk.dll!00007FFC83E39E45: (caller: 00007FFC83EA227D) ReturnHr(3) tid(21cc) 80004002 不支持此接口
too difficult to locate the root cause of these kind of error
Fault stack looks like this:
KernelBase.dll!RaiseException(unsigned long dwExceptionCode, unsigned long dwExceptionFlags, unsigned long nNumberOfArguments, const unsigned __int64 * lpArguments) Line 954 C
combase.dll!SendReport(HRESULT error, unsigned int cchMax, const wchar_t * message, unsigned short pSid, void * pExceptionObject, IUnknown *) Line 434 C++
combase.dll!RoOriginateErrorW(HRESULT error, unsigned int cchMax, const wchar_t * message) Line 570 C++
[Inline Frame] Microsoft.UI.Input.dll!Microsoft::WRL2::ContextRuntimeClass::ReportDisposed() Line 698 C++
Microsoft.UI.Input.dll!PreTranslateKeyboardInputWinRT::ComApi::SetPreTranslateHandler(Microsoft::UI::Input::IInputPreTranslateKeyboardSourceHandler * handler) Line 53 C++
Microsoft.ui.xaml.dll!CXamlIslandRoot::UnsubscribeToInputEvents() Line 1495 C++
Microsoft.ui.xaml.dll!CXamlIslandRoot::Dispose() Line 80 C++
Microsoft.ui.xaml.dll!DirectUI::DesktopWindowXamlSource::Close() Line 490 C++
Microsoft.ui.xaml.dll!DirectUI::DesktopWindowImpl::Shutdown() Line 1091 C++
Microsoft.ui.xaml.dll!DirectUI::DesktopWindowImpl::CloseImpl() Line 471 C++ Microsoft.ui.xaml.dll!DirectUI::DesktopWindowImpl::OnMessage(const unsigned int uMsg, const unsigned __int64 wParam, const __int64 lParam) Line 693 C++
Microsoft.ui.xaml.dll!BaseWindow<DirectUI::DesktopWindowImpl>::WndProc(HWND__ * const window, const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 91 C++
The object was disposed at this stack (or at least the "are you disposed?" bool was set here...)
0:004> kc 20
# Call Site
00 Microsoft_UI_Input!Microsoft::WRL2::ContextRuntimeClass::PostDestroy
01 Microsoft_UI_Input!Microsoft::WRL2::ContextRuntimeClass::ProcessDestroyWorkflow
02 Microsoft_UI_Input!Microsoft::WRL2::ContextRuntimeClass::Dispose
03 Microsoft_UI_Input!Microsoft::WRL2::ContextRuntimeClass::Close
04 Microsoft_UI_Input!CloseComPtr<BaseInputObjectWinRT>
05 Microsoft_UI_Input!InputSiteWinRT::Destroy
06 Microsoft_UI_Input!Microsoft::WRL2::ContextRuntimeClass::ProcessDestroyWorkflow
07 Microsoft_UI_Input!Microsoft::WRL2::ContextRuntimeClass::Dispose
08 Microsoft_UI_Input!Microsoft::WRL2::ContextRuntimeClass::Close
09 Microsoft_UI_Input!WindowsMessageDeliveryInputSiteWinRT::WindowDestroyed_Callback
0a Microsoft_UI_Input!WindowsMessageDeliveryAdapter::ProcessWindowMessage_NoLock
0b Microsoft_UI_Input!WindowsMessageDeliveryAdapter::StaticSubclassWndProc_NoLock
0c Microsoft_UI_Input!WindowsMessageDeliveryAdapter::s_FeatureProc
0d Microsoft_UI_Windowing_Core!Core::YieldAndCall::FeatureProc
0e Microsoft_UI_Windowing_Core!Windowing::ExternalFeature::FeatureProc
0f Microsoft_UI_Windowing_Core!Windowing::FeatureCallContext::CallNextHandler
10 Microsoft_UI_Windowing_Core!Windowing::FeatureCallManager::CallFeatureChain
11 Microsoft_UI_Windowing_Core!Windowing::Window::ProcessMessage
12 Microsoft_UI_Windowing_Core!Windowing::Window::ProcessWindowMessage
13 Microsoft_UI_Windowing_Core!EnterContextAndProcessWindowMessage
14 USER32!UserCallWinProcCheckWow
15 USER32!DispatchClientMessage
16 USER32!__fnNCDESTROY
17 ntdll!KiUserCallbackDispatcherContinue
18 win32u!ZwUserDestroyWindow
19 Microsoft_UI_Input!DesktopSiteBridge::Destroy
1a Microsoft_UI_Input!DesktopChildSiteBridge::Destroy
1b Microsoft_UI_Input!ContentSiteBridge::ProcessDestroy
1c Microsoft_UI_Input!ContentSiteBridge::Close
1d Microsoft_UI_Xaml!DirectUI::DesktopWindowXamlSource::Close
I agree this is annoying to debugging, but not fatal.
@JesseCol fyi