Debugger hangs for iOS app, made worse by native code
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
Visual Studio debugger disconnects/hangs when debugging .NET MAUI iOS app using Behavior/Binding font auto-sizing + heavy Trace; Label.Measure returns (0,0); native measurement worsens
## Summary
When debugging a .NET MAUI app on a physical iPhone, Visual Studio frequently disconnects the debugger during startup and may hang (needs Task Manager kill) or exit/restart. This correlates with using Behaviors/Bindings to auto-size fonts (uniform sizing across controls/list items) and is strongly affected by the amount of Trace.WriteLine output. The app runs fine when started without the debugger attached.
Also, Label.Measure(...) returns (0,0) in this scenario, which led to adding platform-specific/native text measurement code; that native code seems to make the debugger instability worse.
## Environment
- Visual Studio 2026, February 2026 Feature Update, 18.3.2
- Windows 11 Home 25H2
- .NET 10.0
- Syncfusion 32.2.7
- Mac build host (latest Xcode), paired over Wi‑Fi; iPhone connected to Mac via USB
- Target: iPhone 15 Pro Max
## What the app is doing
- Uses Binding + Behavior to:
- find the longest string across datasets (e.g., 4 tabs of ListViews)
- compute a font size so related items share a uniform size and fit available space
## Repro (high level)
1. Debug MAUI iOS app on physical iPhone (Windows VS → Mac host → iPhone).
2. During startup, produce moderate/heavy Trace.WriteLine output.
3. Trigger font auto-sizing logic across many list items (button populates dicts feeding multiple ListViews/tabs).
4. Observe debugger disconnects and/or VS hangs.
## Expected
- Debugger remains attached; Visual Studio remains responsive.
- Label.Measure(...) returns non-zero size for non-empty text.
## Actual
- Debugger disconnects during startup; breakpoints are hard/impossible to set before disconnect.
- More Trace.WriteLine output increases likelihood of disconnect.
- After disconnect, VS may hang or restart.
- Triggering font auto-sizing often hangs VS.
- Label.Measure(...) returns (0,0).
- Platform-specific/native text measurement code makes the debugging problem worse.
## Platform-specific measurement workaround (seems to worsen debugger stability)
```csharp
public static (double Width, double Height) MeasureText(string textIn, double fontSize, string fontFamily)
{
if (string.IsNullOrEmpty(textIn))
return (0, 0);
string text1 = new String('A', textIn.Length / 2);
string text2 = new String('a', textIn.Length / 2);
string text = text1 + text2;
#if ANDROID
using var paint = new Android.Graphics.Paint(PaintFlags.AntiAlias);
paint.TextSize = (float)fontSize;
if (!string.IsNullOrEmpty(fontFamily))
paint.SetTypeface(Typeface.Create(fontFamily, TypefaceStyle.Normal));
double width = paint.MeasureText(text);
var metrics = paint.GetFontMetrics();
double height = metrics.Descent - metrics.Ascent;
return (width, height);
#endif
#if IOS || MACCATALYST
UIFont uiFont = !string.IsNullOrEmpty(fontFamily)
? (UIFont.FromName(fontFamily, (nfloat)fontSize) ?? UIFont.SystemFontOfSize((nfloat)fontSize))
: UIFont.SystemFontOfSize((nfloat)fontSize);
var attributes = new UIStringAttributes { Font = uiFont };
var ns = new NSString(text);
var maxSize = new CGSize(double.MaxValue, double.MaxValue);
var rect = ns.GetBoundingRect(maxSize, NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null);
return (rect.Width, rect.Height);
#endif
return (0, 0);
}
```
### Steps to Reproduce
_No response_
### Link to public reproduction project repository
_No response_
### Version with bug
11.0.0-preview.1
### Is this a regression from previous behavior?
Not sure, did not test other versions
### Last version that worked well
Unknown/Other
### Affected platforms
Windows, iOS
### Affected platform versions
_No response_
### Did you find any workaround?
_No response_
### Relevant log output
```shell
```
Contributor guide
Research direction
No project files, tests, or public reproduction are provided. Start by isolating the supplied startup sequence around Label.Measure(...), Binding/Behavior font auto-sizing, Trace.WriteLine output, and the native MeasureText workaround; done requires a reproducible debugger disconnect or hang and confirmed non-zero measurement for non-empty text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, ios
- Domain
- devtools, mobile-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100