Description
Describe the bug
I have a Multi Window application:
My mainwindow activates WindowA. If the close button in WindowA is pressed, I call 'this->Close();' and WindowA closes, but sometimes it triggeres:
template auto consume_Microsoft_UI_Xaml_IWindow::Close() const
{
check_hresult(WINRT_IMPL_SHIM(winrt::Microsoft::UI::Xaml::IWindow)->Close());
}
of the App.exe!winrt::impl::consume_Microsoft_UI_Xaml_IWindowwinrt::myApp::implementation::WindowB::Close() Zeile 4634 C++ (from Debuggers Call Chain)
But this WindowB wasn't activated so i Get this Exception:
Ausnahmefehler bei 0x00007FF8B3616DC0 (combase.dll) in App.exe: 0xC0000602: Ein sofortiger Ausnahmefehler ist aufgetreten. Die Ausnahmehandler werden nicht aufgerufen, und der Prozess wird sofort beendet
Ausnahme ausgelöst bei 0x00007FFFB7EE9853 (Microsoft.ui.xaml.dll) in App.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x0000000000000018.
My debug output: (this is a mix of Visual Studio debug output and my own Exception log..)
Ausnahmefehler bei 0x00007FFFB79ADD55 (Microsoft.ui.xaml.dll) in App.exe: 0xC000027B: Anwendungsinterne Ausnahme (Parameter: 0x0000023AA0275B50, 0x0000000000000001)
Ausnahmefehler bei 0x00007FF8B3616DC0 (combase.dll) in App.exe: 0xC0000602: Ein sofortiger Ausnahmefehler ist aufgetreten. Die Ausnahmehandler werden nicht aufgerufen, und der Prozess wird sofort beendet
Ausnahme ausgelöst bei 0x00007FFFB7EE9853 (Microsoft.ui.xaml.dll) in App.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x0000000000000018.
250506_08:59:03.1999722 ERR App: Exception: Code: C0000005 @ 0x7FFFB7EE9853 | Access Violation: Read @ 0x0000000000000018
Ausnahme ausgelöst bei 0x00007FF8B247831A (KernelBase.dll) in App.exe: 0x80010105: Ausnahmefehler des Servers.
Ausnahme ausgelöst bei 0x00007FF8B247831A (KernelBase.dll) in App.exe: WinRT originate error - 0x80010105 : 'Ausnahmefehler des Servers.'.
Ausnahme ausgelöst bei 0x00007FF8B247831A in App.exe: Microsoft C++-Ausnahme: winrt::hresult_error bei Speicherort 0x00000093CC89F7F0.
Ausnahme ausgelöst bei 0x00007FF8B247831A in App.exe: Microsoft C++-Ausnahme: winrt::hresult_error bei Speicherort 0x00000093CC89D370.
250506_08:59:05.0136242 ERR App: Exception: Code: 80010105 @ 0x7FF8B247831A | Unknown Exception
250506_08:59:05.0137460 ERR App: WinRT Exception: unknown @ D:\Projects\source\myAPP\myAPP\myAPP\Generated Files\winrt\base.h : 9183 | HRESULT: 0x80010105 | Description: Ausnahmefehler des Servers.
250506_08:59:05.0141353 ERR App: Exception: Code: 40080201 @ 0x7FF8B247831A | WinRT internal parse error
250506_08:59:05.0143379 ERR App: WinRT Exception: unknown @ D:\Projects\source\myAPP\myAPP\myAPP\Generated Files\winrt\base.h : 9183 | HRESULT: 0x80010105 | Description: Ausnahmefehler des Servers.
250506_08:59:05.0147444 ERR App: Exception: Code: E06D7363 @ 0x7FF8B247831A | C++ Exception
250506_08:59:05.0151490 ERR App: Exception: Code: E06D7363 @ 0x7FF8B247831A | C++ Exception
As result of this the WindowA stays open (black).
If I click on it again I get:
Ausnahme ausgelöst bei 0x00007FFFB7738967 (Microsoft.ui.xaml.dll) in UniHarp.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x0000000000000058.
in
template auto consume_Microsoft_UI_Xaml_IApplicationStatics::Start(winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback const& callback) const
{
check_hresult(WINRT_IMPL_SHIM(winrt::Microsoft::UI::Xaml::IApplicationStatics)->Start(*(void**)(&callback)));
}
Steps to reproduce the bug
.
Expected behavior
No response
Screenshots
No response
NuGet package version
None
Packaging type
No response
Windows version
No response
IDE
No response
Additional context
No response
Activity
tpoint75 commentedon May 6, 2025
'this->Close();' has to be 'this->get_strong()->Close();'
[-]Bug title[/-][+]Calling this->Close() on a Window sometimes throws an Access Violation exception[/+]tpoint75 commentedon May 15, 2025
this->get_strong()->Close();
also sometimes throwes
C0000005 @ 0x7FFFA1EB9853 | Access Violation: Read @ 0x0000000000000018
Whats the right way to close a app window?
winrt::Microsoft::UI::Xaml::Window::Current().Close();
throws
C0000005 @ 0x7FF6AFF90182 | Access Violation: Read @ 0x0000000000000000