microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.18k stars 667 forks source link

WinUI 3 application throwing 'Reentrancy was detected in this XAML application' #8974

Open Ajith-GS opened 9 months ago

Ajith-GS commented 9 months ago

Describe the bug

A WinUI 3 application is throwing the following exception while running:

'Reentrancy was detected in this XAML application. Use a debugger to locate the reentrant code and, if necessary, move that code to an asynchronous event handler. Press OK to exit the application.'.

The UI contains minimum XAML components, but we couldn't find the reason behind the exception. The exception is not reproducible every time, but it is not rare (~ 1/10). Is there any way to fix this issue or is there any workaround available?

Steps to reproduce the bug

  1. Create a C++ WinUI3 project using "Blank App, Packaged (WinUI 3 in Desktop)" template.

  2. Make it as unpackaged application using the steps described in the following link. https://learn.microsoft.com/en-us/windows/apps/winui/winui3/create-your-first-winui3-app#unpackaged-create-a-new-project-for-an-unpackaged-c-or-c-winui-3-desktop-app

  3. Replace the Main Window XAML code with following XAML. CodeSnippet

  4. Build the application.

  5. Run the application in Visual Studio and observe the output window, or run the application without debugging mode and the application will be crashed.

Expected behavior

The application should run without any exception or crash.

Screenshots

Exception message in output window. OutputWindow

NuGet package version

Windows App SDK 1.4.1: 1.4.230913002

Packaging type

Packaged (MSIX), Unpackaged

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

An unpackaged sample application with given issue is attached. SampleApp.zip

Any help would be greatly appreciated.

HHaoWang commented 9 months ago

I got the same error. I am using a gridView with a ContainerContentChanging event to render item's image. Images are loaded from storage and I have a static method to get them. When opening this page where gridView belongs, VS debugger stop and say there is an unhandled exception: 0x00007FFB407A95E4 (Microsoft.ui.xaml.dll) (FreeKTV.exe 中)处有未经处理的异常: 0xC000027B: 发生应用程序内部异常。 (参数: 0x000002E33B4CD570, 0x0000000000000004)。 image

Here is the event handler which calls the code in the picture above: image

After clicking continue buttion, the application runs normally as nothing happens. It's weird and I don't know how to fix it.

Patschkowski commented 5 months ago

I ran into a similar issue. In my case I am using a GridView and the underlying data collection implements winrt::Microsoft::UI::Xaml::Data::ISupportIncrementalLoading. The GridView uses the attached dependency properties ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible". This enables UI and data virtualization.

Looks to me like the reentrancy is caused by SetValue and/or GetValue.

TommiGustafsson-HMP commented 1 month ago

We've got the same error here: https://github.com/microsoft/microsoft-ui-xaml/issues/9736

It appears within 10 minutes into playing the game, using SwapChainPanel (GPU Acceleration).