Skip to content

Fix: iOS null exception occurs on Toolkit SfButton when text is null#386

Merged
PaulAndersonS merged 1 commit into
mainfrom
bugfix/maui-ios-sfbutton-null-exception
Jun 1, 2026
Merged

Fix: iOS null exception occurs on Toolkit SfButton when text is null#386
PaulAndersonS merged 1 commit into
mainfrom
bugfix/maui-ios-sfbutton-null-exception

Conversation

@KarthikaRSF4617
Copy link
Copy Markdown
Collaborator

@KarthikaRSF4617 KarthikaRSF4617 commented Jun 1, 2026

Root Cause of the Issue

This issue occurs when the SfButton text is set to null, causing a null exception during iOS text measurement.
The existing implementation directly creates an NSString using:

new NSString(text);

On iOS, NSString does not accept null values, which leads to a null exception at runtime.
This scenario can happen when SfButton or its internal text measurement logic triggers measurement before the text is initialized or when text is explicitly null.

Description of Change

Added a null-coalescing safeguard:

text ??= string.Empty;

Ensures that:

  • If text is null, it is replaced with an empty string before creating NSString
  • Prevents runtime exceptions from invalid object initialization

This change guarantees:

  • Safe text measurement execution on iOS
  • No crash when text is missing or not yet initialized
  • Improved stability of SfButton rendering lifecycle

@KarthikaRSF4617 KarthikaRSF4617 changed the title Fix: iOS null exception issue (.NET MAUI Toolkit) Fix: iOS null exception occurs on Toolkit SfButton when text is null Jun 1, 2026
@PaulAndersonS PaulAndersonS merged commit bf5c979 into main Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants