- .net 9 (net9.0-ios)-xamarin/.net для ios
- ios 15/18 (device)
- ancome-interpreter = true
- /> Приложение использует corenfc (iso7816) для чтения счетчика, затем декодирует кадры в большой тип данных
После NFC Scan). /> Возвращение этих данных из пути декодирования /чтения иногда сбой приложения сразу после последней консоли. Изменить это последовательно исправляет, что он поворачивает большой возвратный тип из struct → класс.
// Large result type (originally a struct; switching to class makes crash go away)
public /*struct*/ class Data
{
public Cap Cap;
public Types Type;
public General General;
public Main Main;
// ... many nested value types & arrays ...
}
// Decode on iOS
public override Data Read(Modes mode)
{
var frame = GetFrames();
Console.WriteLine("[trace] getframes completed.");
var result = Decode(frame); // ← builds a big Data value
Console.WriteLine("[trace] decode completed.");
// If I do this (return the real struct), I get sporadic native crashes:
// return result;
// If I do this (dummy), it never crashes:
return new Data();
}
// The hot function (simplified): fills `Result` then returns it
public virtual Data Decode(MBus.Frame frame)
{
Result.Cap = Cap;
// ... many assignments into nested fields ...
Console.WriteLine("[trace] Returning Result data");
return Result; // ← returning a big struct
}
```
If I change Data to a class and update code accordingly, crashes stop.
**Minimal native crash excerpt (from .ips and console log)**
No managed stack/exception shows. It’s a native abort:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Crashed Thread: 7
Thread 7 Crashed:
0 UltraConnect.iOS mono_sigsegv_signal_handler_debug
1 UltraConnect.iOS mono_handle_native_crash
2 UltraConnect.iOS mono_dump_native_crash_info
3 libsystem_platform.dylib _sigtramp
So: native SIGSEGV right after we finish building/returning the large struct; no managed exception surfaces.
**What I tried**
* Verified it’s not UI-thread misuse: crash occurs after decoding completes, on return.
* Added granular logging inside Decode — last log prints; crash happens during/after return path.
* If we read but don’t assign (connectedMeter.Read(Modes.More);) it doesn’t crash. Assigning the returned struct to a variable or passing it onward does (sporadically).
* Switching Data from struct → class eliminates the crash entirely (Android and WPF were always fine).
**Question**
Why would returning a very large, deeply nested struct from AOT’d .NET iOS code cause sporadic native SIGSEGV (no managed exception), while the exact same logic works on Android/WPF — and switching that type to a class fixes it on iOS?
* Is this a known JIT/AOT / marshalling / stack frame issue with large value types on .NET for iOS?
* Are there size/complexity thresholds for value types that can trigger ABI issues during return/copy?
* Any guidance from the runtime/ABI perspective on iOS about returning large structs (copy elision, stack vs. hidden return buffer, interpreter interaction, trimming, etc.)?
**Any pointers to best practices (e.g., prefer classes for large DTOs on iOS, use ref struct/in/out patterns, or known fixes/workarounds) would be hugely appreciated.**
Подробнее здесь: https://stackoverflow.com/questions/797 ... rge-struct
Мобильная версия