"The text associated with this error code could not be found" error with UnitsNet and MVUX model on Windows
igiona opened this issue · 9 comments
Current behavior
Hi
In my application, I have a pretty simple model which contains a UnitsNet Ratio object.
public record DeviceStateModel(
bool OperationIsInProgress,
bool IsConnected,
Ratio? BatteryStateOfCharge
);
I initialize the IState
as follow:
public IState<DeviceStateModel> DeviceState => State<DeviceStateModel>.Value(this, () => new(
false,
false,
null
));
and in different places of the code I updated the model value, for example:
var deviceState = await DeviceState ?? throw new InvalidOperationException("Unable to get the current model state");
await DeviceState.Update(_ => deviceState with { OperationIsInProgress = true, BatteryStateOfCharge = Ratio.FromPercent(Random.Shared.Next(0, 100)) }, CancellationToken.None);
The BatteryStateOfCharge
property is bind as follow:
<TextBlock Text="{Binding DeviceState.BatteryStateOfCharge}" Style="{StaticResource TitleSmall}" VerticalAlignment="Center" />
On iOS&Android I don't issues, on Windows though the after sending the device state update, within 1-2 seconds I get a Microsoft.UI.Xaml.LayoutCycleException
with the following message: Layout cycle detected. Layout could not complete.
The text associated with this error code could not be found.
Layout cycle detected. Layout could not complete.
Expected behavior
The app doesn't crash.
How to reproduce it (as minimally and precisely as possible)
Unfortunately I've not been able to repro this issue with a simple app.
The app with the actual crash is slightly more complex, and uses a BLE connection, SQLite...
I'm not sure if any of this is actually related though.
Any suggestion on what I can debug/further investigate the issue is welcomed.
A repro tentative (which doesn't actually reproduce the issue 😢 ) can be found here: https://github.com/igiona/uno-repro-UnitsNetIssue
Workaround
If I remove the XAML binding, or a change the Ratio?
into a ìnt?` the Exception is not thrown anymore.
Works on UWP/WinUI
No
Environment
No response
NuGet package version(s)
No response
Affected platforms
Windows (WinAppSDK)
IDE
Visual Studio 2022
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
Since I'm not able to easily repro this issue, I still wonder weather Uno has anything to do with the issue itself.
I hope you can give me some hints in order to proceed with the debugging...
Can you set this property and take a look at the output? It may show will control has an issue.
Can you set this property and take a look at the output? It may show will control has an issue.
@jeromelaban I added it in the App ctor:
public App()
{
this.InitializeComponent();
this.DebugSettings.LayoutCycleTracingLevel = LayoutCycleTracingLevel.High;
}
I guess since Uno is not present in WinUI the warning can be ignored, but still I don't see any additional log in the Output/Debug tab.
@igiona You may need to enable native debugging to get this to work.
enable native debugging
Thanks, it helped!
(for the reader that doesn't know what that is as me: https://stackoverflow.com/a/74238776/7157908)
Now I get the logs, and from what I can see it points to AutoLayout
and TextBox
.
Not surprisingly because this is the TextBox
that in my app causes the crash (https://github.com/igiona/uno-repro-UnitsNetIssue/blob/bc36c61b1e1e0c632430bfdbf894e94230ad2ed2/UnitsNetsIssue/Presentation/MainPage.xaml#L21-L23).
The crashing app NavigationBar.Content
looks pretty much the same as the one linked above.
@jeromelaban can you read more out of the logs?
Log
MyApp.Presentation.MainModel: Information: New BSOC BatteryStateOfCharge { Value = 100 % }
[LayoutCycleTracing] Layout Iteration Countdown: 7. Launching Measure Pass.
[LayoutCycleTracing] "Measure(infx64.000000)","LayoutCycleCountdown: 7","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 7","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 7","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(infxinf)","LayoutCycleCountdown: 7","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 21.600000x34.400002 new: 36.799999x17.600000","LayoutCycleCountdown: 7","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] Layout Iteration Countdown: 6. Launching Arrange Pass.
[LayoutCycleTracing] "Arrange(0.000000,0.000000 926.400024x22.400000)","LayoutCycleCountdown: 6","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F674A90","TypeIndex: 702"
[LayoutCycleTracing] "Arrange(880.000000,0.000000 36.799999x22.400000)","LayoutCycleCountdown: 6","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 6","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 6","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(36.799999xinf)","LayoutCycleCountdown: 6","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 36.799999x17.600000 new: 21.600000x34.400002","LayoutCycleCountdown: 6","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] Layout Iteration Countdown: 5. Launching Measure Pass.
[LayoutCycleTracing] "Measure(infx64.000000)","LayoutCycleCountdown: 5","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 5","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 5","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(infxinf)","LayoutCycleCountdown: 5","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 21.600000x34.400002 new: 36.799999x17.600000","LayoutCycleCountdown: 5","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] Layout Iteration Countdown: 4. Launching Arrange Pass.
[LayoutCycleTracing] "Arrange(0.000000,0.000000 926.400024x22.400000)","LayoutCycleCountdown: 4","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F674A90","TypeIndex: 702"
[LayoutCycleTracing] "Arrange(880.000000,0.000000 36.799999x22.400000)","LayoutCycleCountdown: 4","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 4","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 4","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(36.799999xinf)","LayoutCycleCountdown: 4","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 36.799999x17.600000 new: 21.600000x34.400002","LayoutCycleCountdown: 4","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] Layout Iteration Countdown: 3. Launching Measure Pass.
[LayoutCycleTracing] "Measure(infx64.000000)","LayoutCycleCountdown: 3","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 3","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 3","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(infxinf)","LayoutCycleCountdown: 3","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 21.600000x34.400002 new: 36.799999x17.600000","LayoutCycleCountdown: 3","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] Layout Iteration Countdown: 2. Launching Arrange Pass.
[LayoutCycleTracing] "Arrange(0.000000,0.000000 926.400024x22.400000)","LayoutCycleCountdown: 2","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F674A90","TypeIndex: 702"
[LayoutCycleTracing] "Arrange(880.000000,0.000000 36.799999x22.400000)","LayoutCycleCountdown: 2","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 2","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 2","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(36.799999xinf)","LayoutCycleCountdown: 2","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 36.799999x17.600000 new: 21.600000x34.400002","LayoutCycleCountdown: 2","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] Layout Iteration Countdown: 1. Launching Measure Pass.
[LayoutCycleTracing] "Measure(infx64.000000)","LayoutCycleCountdown: 1","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 1","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 1","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(infxinf)","LayoutCycleCountdown: 1","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 21.600000x34.400002 new: 36.799999x17.600000","LayoutCycleCountdown: 1","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] Layout Iteration Countdown: 0. Launching Arrange Pass.
[LayoutCycleTracing] "Arrange(0.000000,0.000000 926.400024x22.400000)","LayoutCycleCountdown: 0","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F674A90","TypeIndex: 702"
[LayoutCycleTracing] "Arrange(880.000000,0.000000 36.799999x22.400000)","LayoutCycleCountdown: 0","ClassName: Uno.Toolkit.UI.AutoLayout","Instance: 0x0000028D2F6777F0","TypeIndex: 702"
[LayoutCycleTracing] "SetValue(VerticalAlignment=1)","LayoutCycleCountdown: 0","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "SetValue(HorizontalAlignment=2)","LayoutCycleCountdown: 0","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "Measure(36.799999xinf)","LayoutCycleCountdown: 0","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
[LayoutCycleTracing] "DesiredSize changed, old: 36.799999x17.600000 new: 21.600000x34.400002","LayoutCycleCountdown: 0","ClassName: Microsoft.UI.Xaml.Controls.TextBlock","Instance: 0x0000028D2F75E940","TypeIndex: 616"
Microsoft.ui.xaml.dll!00007FF81F23D4A5: CallContext:[\ImageDecodeActivity] 88000FA8 - AG_E_LAYOUT_CYCLE
Layout Iteration Countdown: 7. Launching Measure Pass.
Layout Iteration Countdown: 6. Launching Arrange Pass.
Layout Iteration Countdown: 5. Launching Measure Pass.
Layout Iteration Countdown: 4. Launching Arrange Pass.
Layout Iteration Countdown: 3. Launching Measure Pass.
Layout Iteration Countdown: 2. Launching Arrange Pass.
Layout Iteration Countdown: 1. Launching Measure Pass.
Layout Iteration Countdown: 0. Launching Arrange Pass.
Exception thrown at 0x00007FF92B23F39C (KernelBase.dll) in MyApp.exe: WinRT originate error - 0x802B0014 : 'Layout cycle detected. Layout could not complete.'.
@carldebilly this looks like an autolayout issue, could you take a look?
@jeromelaban I guess you mean this?
Can I bump only the toolkit to 6.0.24 or is there already a "Uno.Sdk" 5.2 release I can use?
Thanks! At this time, there's no uno.sdk which uses that version, we're working on unifying versions so that this upgrade scenario gets easier. In the meantime, you can change the version in your Directory.Build.props
file.
I confirm that with the toolkit version 6.0.24
this issue is fixed 👏
Once again, thank you for the great support!