dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.97k stars 1.71k forks source link

FlexLayouts and ScrollViews cause unhandled InvalidOperationException in WinRT.Runtime.dll with message "Element not found" #18780

Open busitech opened 9 months ago

busitech commented 9 months ago

Description

App crashes on startup. There is no practical way to debug this problem, because all of the code in the stack is in the System namespace, and coming up from the COM Interop layer as a COMException. The most meaningful Exception thrown is: 'System.InvalidOperationException' in WinRT.Runtime.dll

System.InvalidOperationException: Operation is not valid due to the current state of the object. The program '[2268] FlexLayoutTest.exe' has exited with code 3221226107 (0xc000027b).

There is also a Message of "Element not found." in the UnhandledExceptionEventArgs.

Stack Trace 1:

FlexLayoutTest.dll!FlexLayoutTest.WinUI.App.InitializeComponent.AnonymousMethod__3_1(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) Line 68
    at C:\FlexLayoutTest\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs(68)
Microsoft.WinUI.dll!WinRT._EventSource_global__Microsoft_UI_Xaml_UnhandledExceptionEventHandler.EventState.GetEventInvoke.AnonymousMethod__1_0(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) Line 21
    at WinRT\_EventSource_global__Microsoft_UI_Xaml_UnhandledExceptionEventHandler.cs(21)
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.UnhandledExceptionEventHandler.Do_Abi_Invoke(nint thisPtr, nint sender, nint e) Line 137
    at ABI.Microsoft.UI.Xaml\UnhandledExceptionEventHandler.cs(137)
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.Start(WinRT.IObjectReference _obj, Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Line 18
    at ABI.Microsoft.UI.Xaml\IApplicationStaticsMethods.cs(18)
Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Line 229
    at Microsoft.UI.Xaml\Application.cs(229)
FlexLayoutTest.dll!FlexLayoutTest.WinUI.Program.Main(string[] args) Line 31
    at C:\FlexLayoutTest\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs(31)

Stack Trace 2:

WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|20_0(int hr) Line 103
    at WinRT\ExceptionHelpers.cs(103)
WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr) Line 105
    at WinRT\ExceptionHelpers.cs(105)
Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll!ABI.Microsoft.Windows.ApplicationModel.WindowsAppRuntime.IDeploymentManagerStatics2Methods.Initialize(WinRT.IObjectReference _obj, Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentInitializeOptions deploymentInitializeOptions) Line 491
    at D:\a\_work\1\s\obj\Release\arm64\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection\Generated Files\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.cs(491)
Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll!Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentManager.Initialize(Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentInitializeOptions deploymentInitializeOptions) Line 161
    at D:\a\_work\1\s\obj\Release\arm64\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection\Generated Files\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.cs(161)
Microsoft.Maui.dll!Microsoft.Maui.DeploymentManagerAutoInitializer.AccessWindowsAppSDK() Line 23
    at Microsoft.Maui\DeploymentManagerAutoInitializer.cs(23)
Microsoft.Maui.dll!<Module>.<Module>() Line 8
    at -\-Module-.cs(8)
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.ApplicationInitializationCallback.Do_Abi_Invoke(nint thisPtr, nint p) Line 134
    at ABI.Microsoft.UI.Xaml\ApplicationInitializationCallback.cs(134)
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.Start(WinRT.IObjectReference _obj, Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Line 18
    at ABI.Microsoft.UI.Xaml\IApplicationStaticsMethods.cs(18)
Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Line 229
    at Microsoft.UI.Xaml\Application.cs(229)
FlexLayoutTest.dll!FlexLayoutTest.WinUI.Program.Main(string[] args) Line 31
    at C:\FlexLayoutTest\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs(31)

Steps to Reproduce

Run the reproducer, and observe the crash.

Link to public reproduction project repository

https://github.com/busitech/FlexLayoutScrollViewBug1

Version with bug

7.0.101

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10.0.19045.3636

Did you find any workaround?

The only workaround is to compromise the desired functionality by removing some FlexLayouts or ScrollViews until a combination allows the app to start.

Relevant log output

No response

busitech commented 9 months ago

The test application will start successfully on macOS.

XamlTest commented 9 months ago

Verified this on Visual Studio Enterprise 17.9.0 Preview 1(8.0.3). Repro on Windows 11, not repro on MacCatalyst with below Project: FlexLayoutScrollViewBug1.zip