question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[MAUI-Windows] Unhandled layout cycle exception occurs when setting "IsVisible = False" inside FlexLayout

See original GitHub issue

Description

I am trying to add a view (say Grid) inside a FlexLayout. After added the view, when I set “IsVisible” property of the grid at the run time. I am facing the below unhandled exception

Exception: “A cycle occurred while laying out the GUI.” Message: “Layout cycle detected. Layout could not complete.”

image

Note: This occurs with all kind of MAUI views inside a FlexLayout.

Steps to Reproduce

  1. Create a new MAUI App.
  2. Add a view (say grid) inside the flex layout.
  3. Use a switch control to to toggle the visibility of the view at the run time.
  4. Run the sample.
  5. Disable the view at the run time by setting its property “IsVisible=false”. Now the unhandled Exception will be thrown.

I have attached a sample to reproduce the issue. MauiApp1.zip

Run the attached sample and toggle the switch control “Make Visible”, in the left top of the app.

Version with bug

6.0.419

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows SDK 10.0.19041

Did you find any workaround?

No

Relevant log output

No logs obtained due to unhandled exception occurs.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
AppXturecommented, Aug 13, 2022

I’m having similar issues that started today after updating VS 2022 to 17.3 and VS2022 Preview to 17.4.

My steps to reproduce is that I have a FlexLayout on a ContentPage and if I add anything to it then I get the error. If I comment out the FlexLayout or it’s contents then no error.

It’s been working fine until the latest Visual Studio updates. Not sure which version of Windows SDK I was on before but I’m on 10.0.19041 now.

1reaction
holecekpcommented, Nov 23, 2022

I have installed the latest 7.0.49 version and my app is still crashing as before. I first thought that the bug has not been fixed. But then I noticed that the error message is different and that it crashes after the update even if I remove the flex layout. I have downloaded the repro project from this issue, and tried it with the latest .net6 and .net7 version, and it works without crashing.

So yes, this bug has been fixed but it was replaced by another one that crashes the app in different more general situations. If I have time, I will try to find the problem, create a repro project and file a new issue for it. It seems that MAUI on .NET 7 have problem with some lazily-loaded views (even without flex layout) that used to work in Xamarin.Forms and older versions of MAUI. When a lazily-loaded view should be loaded and the LazyView.Content is set to the newly created view, the app crashes:

Exception thrown: 'System.InvalidOperationException' in Microsoft.Maui.dll
The handler's MauiContext cannot be null.

This is a Windows-only problem. It works on Android. I will investigate it more and file a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FlexLayout isn't displaying the bindable data in .NET Maui?
This is a known problem in FlexLayout. It has nothing to do with bindable data. I wrote a simple demo based on your...
Read more >
I'm getting an exception error Layout cycle detected
I am developing my application on a parralels virtual machine, not sure if this is the problem. .NET MAUI.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found