Bug 56843 - Embedding UWP Native View in StackLayout with certain LayoutOption configurations causes runtime LayoutCycleException
Summary: Embedding UWP Native View in StackLayout with certain LayoutOption configurat...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.4
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Chris King
URL:
Depends on:
Blocks:
 
Reported: 2017-05-25 17:22 UTC by Adam Patridge [MSFT]
Modified: 2017-06-23 17:59 UTC (History)
3 users (show)

Tags: ac fr
Is this bug a regression?: ---
Last known good build:


Attachments
Repro solution with test cases and notes (290.33 KB, application/x-zip-compressed)
2017-05-25 17:22 UTC, Adam Patridge [MSFT]
Details
VS 2015 w/o XAML (343.23 KB, application/x-zip-compressed)
2017-06-07 14:47 UTC, Chris King
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Adam Patridge [MSFT] 2017-05-25 17:22:33 UTC
Created attachment 22465 [details]
Repro solution with test cases and notes

When I embed a UWP TextBlock native view in a StackLayout with HorizontalOptions and VerticalOptions that don't include at least one "Fill" value, running the app will cause a LayoutCycleException when the app launches.

## Steps

1. New Project: Cross-Platform > Cross Platform App > Blank App (Forms + Shared)
2. Open the generated MainPage.xaml
3. Add the Windows namespace (e.g., `xmlns:win="clr-namespace:Windows.UI.Xaml.Controls;assembly=Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime;targetPlatform=Windows"` that I pulled from https://developer.xamarin.com/guides/xamarin-forms/platform-features/native-views/)
4. Wrap the existing Label in a fully-centered StackLayout (HorizontalOptions and VerticalOptions set to "Center", though some other combinations also trigger the issue)
5. Add a UWP Native View to the new StackLayout

Resulting MainPage:
```
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App1"
             xmlns:win="clr-namespace:Windows.UI.Xaml.Controls;assembly=Windows, Version=255.255.255.255,
            Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime;targetPlatform=Windows"
             x:Class="App1.MainPage">

    <StackLayout VerticalOptions="Start" 
               HorizontalOptions="Center">
        <Label Text="Welcome to Xamarin Forms!" 
               VerticalOptions="Center" 
               HorizontalOptions="Center" />
        <win:TextBlock Text="Hello World" />
    </StackLayout>

</ContentPage>
```

## Expected Result

When run on a UWP platform, it should show a Label and a UWP TextBlock centered in the app window.

## Actual Result

Runtime exception in App.g.i.cs in the UnhandledException block.

e = {Windows.UI.Xaml.UnhandledExceptionEventArgs}
  Exception = {Windows.UI.Xaml.LayoutCycleException: A cycle occurred while laying out the GUI.}
  Message = "Layout cycle detected.  Layout could not complete."

I've attached a repro solution that includes a bunch of test cases I've tried, as well as their success/fail status.

## Additional Details

In the repro steps above, if you change the StackLayout to the default (Fill) in either direction, it will render fine. If you change it to Horizontal of "Start" and Vertical of "Center", it will have the same exception above. I haven't tested all combinations involving "*AndExpand" options yet.

Of the non-AndExpand LayoutOption tests I've run, it only seems to work when one of them is Fill.

This happens with the latest VS 2017.2 ("15.2 (26430.6) Release") and VS 2017.3 Preview ("15.3 (26510.0-Preview) Preview").

## Setup Info

UWP Project NuGet Highlights

* Microsoft.NETCore.UniversalWindowsPlatform v5.3.3
* Xamarin.Forms v2.3.4.247

Truncated Visual Studio info

Microsoft Visual Studio Enterprise 2017 Preview (2)
Version 15.3 (26510.0-Preview) Preview
VisualStudio.15.Preview/15.3.0-Preview+26510.0
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

...

Visual C# 2017   00369-60000-00001-AA352
Microsoft Visual C# 2017

...

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

...

Visual Studio Tools for Universal Windows Apps   15.0.26510.00
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.IoT   1.0
Package with IoT components for Visual Studio

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   4.6.0.560 (33bfa20)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.3.0.13 (448f54f)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.11.0.126 (7571635)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Comment 1 Paul DiPietro [MSFT] 2017-05-29 18:39:28 UTC
Also checked against the nightly where it's still occurring.
Comment 2 Chris King 2017-06-07 14:47:28 UTC
Created attachment 22750 [details]
VS 2015 w/o XAML

You'll need to re-install XF nuget package with your own private version.