Skip to content

Binding the Description property on a SettingsCard to string.Empty causes a crash #310

@brooke-tilley

Description

@brooke-tilley

Describe the bug

When the Description property on CommunityToolkit.WinUI.Controls.SettingsCard is bound to a property which returns an empty string, there's an E_INVALIDARG crash from within WinUI, specifically within FrameworkElement.MeasureOverride.

As far as I can tell, it seems to happen when some element requests to be laid out despite having zero size. However, binding the Text property on a TextBlock to the empty string doesn't produce the same behaviour, so I'm not sure why it happens in SettingsCard specifically.

The callstack at time of crash is absolutely tremendous, but here are the top few frames for the curious:

WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|39_0(int hr)	Unknown
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IFrameworkElementOverridesMethods.MeasureOverride(WinRT.IObjectReference _obj, Windows.Foundation.Size availableSize) Line 17835	C#
Microsoft.WinUI.dll!Microsoft.UI.Xaml.FrameworkElement.MeasureOverride(Windows.Foundation.Size availableSize) Line 4156	C#
Microsoft.WinUI.dll!Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.MeasureOverride(Windows.Foundation.Size availableSize) Line 4158	C#
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_MeasureOverride_0(nint thisPtr, Windows.Foundation.Size availableSize, Windows.Foundation.Size* result) Line 17894	C#

Steps to reproduce

SomePage.xaml

<controls:SettingsCard Header="Foo" Description="{x:Bind SomeProperty}" />

SomePage.xaml.cs

public string SomeProperty => string.Empty;

Expected behavior

I expected the settings card to not crash, and simply render with an empty description field.

Screenshots

No response

Code Platform

  • UWP
  • WinAppSDK / WinUI 3
  • Web Assembly (WASM)
  • Android
  • iOS
  • MacOS
  • Linux / GTK

Windows Build Number

  • Windows 10 1809 (Build 17763)
  • Windows 10 1903 (Build 18362)
  • Windows 10 1909 (Build 18363)
  • Windows 10 2004 (Build 19041)
  • Windows 10 20H2 (Build 19042)
  • Windows 10 21H1 (Build 19043)
  • Windows 10 21H2 (Build 19044)
  • Windows 10 22H2 (Build 19045)
  • Windows 11 21H2 (Build 22000)
  • Other (specify)

Other Windows Build number

Windows 11 23H2 (Build 22631)

App minimum and target SDK version

  • Windows 10, version 1809 (Build 17763)
  • Windows 10, version 1903 (Build 18362)
  • Windows 10, version 1909 (Build 18363)
  • Windows 10, version 2004 (Build 19041)
  • Windows 10, version 2104 (Build 20348)
  • Windows 11, version 22H2 (Build 22000)
  • Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

Version 17.8.3

Device form factor

Desktop

Additional context

For those encountering the same issue, I have worked around it for the time being by passing a single space character to the property, rather than the empty string.

Help us help you

No, I'm unable to contribute a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions