Skip to content

Label with FormattedText crashes with OutOfMemoryException in RecalculateSpanPositions on Windows when text exceeds ~150 characters #35527

Closed

Description

@xiedong2000

Description

On Windows, binding a Label.FormattedTextProperty to a FormattedString containing ~150+ characters causes an OutOfMemoryException during layout. The crash occurs in FormattedStringExtensions.RecalculateSpanPositions. iOS and Android are unaffected — they handle span position tracking natively.

This appears related to the stale issue #28171, which identified an infinite loop in the same method when defaultLineHeight == 0.

Steps to Reproduce

Create a Label bound to Label.FormattedTextProperty via a converter that returns a FormattedString with Span objects
Set the text value to ~150+ characters
Trigger a layout pass (e.g. toggling IsEnabled on a parent, navigation, or visibility change)
Expected Behavior
The label renders the text without crashing.

Actual Behavior
App crashes with:

System.OutOfMemoryException: Array dimensions exceeded supported range.
at System.Collections.Generic.List`1.set_Capacity(Int32 value)
at Microsoft.Maui.Controls.Platform.FormattedStringExtensions.RecalculateSpanPositions(TextBlock control, FormattedString formatted)
at Microsoft.Maui.Controls.Label.RecalculateSpanPositions()
at Microsoft.Maui.Controls.Label.ArrangeOverride(Rect bounds)
at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
at Microsoft.Maui.Controls.VisualElement.set_IsEnabled(Boolean value)

Link to public reproduction project repository

No response

Version with bug

9.0.100 SR10

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

No response

Did you find any workaround?

Skip FormattedString for long text and set Label.Text directly, bypassing RecalculateSpanPositions entirely. This sacrifices clickable link spans in long text but prevents the crash.

Relevant log output

System.OutOfMemoryException: Array dimensions exceeded supported range.
   at System.Collections.Generic.List`1.set_Capacity(Int32 value)
   at Microsoft.Maui.Controls.Platform.FormattedStringExtensions.RecalculateSpanPositions(TextBlock control, FormattedString formatted)
   at Microsoft.Maui.Controls.Label.RecalculateSpanPositions()
   at Microsoft.Maui.Controls.Label.ArrangeOverride(Rect bounds)
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
   at Microsoft.Maui.Controls.VisualElement.set_IsEnabled(Boolean value)

Activity

  1. added
    t/bug
    on May 19, 2026
  2. LogishaSelvarajSF4525 commented on May 21, 2026

    @LogishaSelvarajSF4525
    Contributor

    This issue has been validated in Visual Studio 18.6.0 with .NET MAUI versions 9.0.100, 9.0.120 & 10.0.60. It was not reproducible on Windows platform. I have attached the sample and output for reference:LabelFormattedIssue.zip

    Screen.Recording.2026-05-20.at.12.18.47.PM.mov
  3. Ahamed-Ali commented on May 21, 2026

    @Ahamed-Ali
    Contributor

    @xiedong2000 Can you provide a replication sample or modify the above sample to replicate the issue? That will help us investigate further more quickly.

  4. added
    s/needs-info
    s/needs-repro
    on May 21, 2026
  5. xiedong2000 commented on Jul 23, 2026

    @xiedong2000
    Author

    Here is the demo: https://github.com/xiedong2000/Maui35527Repro

    Your sample applies FormattedText while the Label is visible. The missing ingredient is that the FormattedText must be applied while the Label is hidden (IsVisible="False"), and the text must be long enough to wrap to 3+ lines once shown.

  6. added
    s/needs-attention
    and removed
    s/needs-info
    s/needs-repro
    on Jul 23, 2026
  7. LogishaSelvarajSF4525 commented on Jul 24, 2026

    @LogishaSelvarajSF4525
    Contributor

    This issue has been validated in Visual Studio Professional 2026 Insiders [12009.208] with .NET MAUI versions 10.0.0, 10.0.80 and 10.0.90. It can be reproducible on Windows platform.

    Issue reproduced:

    Screen.Recording.2026-07-24.113154.mp4
  8. added
    s/verified
    s/triaged
    and removed
    s/needs-attention
    on Jul 24, 2026
  9. 8 remaining items

  10. added this to the .NET 10 SR11 milestone on Aug 20, 2026
  11. added 12 commits that reference this issue on Aug 27, 2026
    fca9168
    e09ff32
    99b786b
    3131ba8
    9cd5618
    1cedb36
    3bf35c7
    177deb2
    2c8f963
    b4dfe3d
    fd20de8
    730c956
  12. locked and limited conversation to collaborators on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-labelpartner/syncfusionplatform/windowss/triageds/verifiedt/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions