A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
ObjCRuntime.ObjCException means an Objective‑C exception was thrown by iOS native code and then marshaled into a managed exception at the boundary between .NET and UIKit.
In a .NET for iOS / .NET MAUI app, the managed Program.Main calls UIApplication.Main, which in turn calls the native UIApplicationMain. If any native API (for example, a UIKit or Foundation call) throws an Objective‑C exception during startup, the exception is converted to a managed ObjCException when it crosses back into managed code. That is why the stack trace only shows UIApplicationMain and Program.Main and not the actual failing native call.
Key points from the runtime behavior:
- Managed and Objective‑C exception systems are different. When an Objective‑C exception unwinds through managed frames, the Objective‑C runtime cannot execute managed
catch/finallyblocks, which leads to undefined behavior such as crashes or leaks. - To avoid this, .NET for iOS intercepts calls into Objective‑C (for example,
objc_msgSend) and wraps them in a@try/@catchblock. When anNSExceptionis caught, it is converted to a managed exception and rethrown asObjCRuntime.ObjCExceptionin managed code. - On the main thread,
UIApplicationMainitself is typically wrapped in an Objective‑C@try/@catchthat logs and aborts on unhandled exceptions. When interception is enabled, the runtime converts such Objective‑C exceptions to managed exceptions at the managed/native boundary so they can be observed asObjCException.
Because of this design, the ObjCException in Program.Main does not originate there; it indicates that some earlier native call (often a UI or platform API used during app startup) threw an NSException. To diagnose the root cause, it is necessary to inspect the native exception details (message such as NSInvalidArgumentException, selector name, etc.) and the native stack frames, which are not shown in the snippet.
If needed, the behavior of this marshaling can be adjusted via the MSBuild properties MarshalManagedExceptionMode and MarshalObjectiveCExceptionMode, which control how managed and Objective‑C exceptions are intercepted and converted at build time. However, changing these modes only affects how exceptions are propagated; it does not fix the underlying native error that caused the ObjCException.
References: