You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Label with FormattedText crashes with OutOfMemoryException in RecalculateSpanPositions on Windows when text exceeds ~150 characters #35527
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)
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
@xiedong2000 Can you provide a replication sample or modify the above sample to replicate the issue? That will help us investigate further more quickly.
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.
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.
Activity
LogishaSelvarajSF4525 commentedon May 21, 2026
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
Ahamed-Ali commentedon May 21, 2026
@xiedong2000 Can you provide a replication sample or modify the above sample to replicate the issue? That will help us investigate further more quickly.
xiedong2000 commentedon Jul 23, 2026
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.
LogishaSelvarajSF4525 commentedon Jul 24, 2026
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 remaining items
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…
[Windows]Fix: Label Formatted Text crashed with out of memory Excepti…