Share via

Exception has occurred: CLR/ObjCRuntime.ObjCException

Sreenivasan, Sreejith 740 Reputation points
2026-04-09T10:13:14.8533333+00:00

I am facing below issue in my MAUI project on Visual Studio code for Mac:

abcd

Exception has occurred: CLR/ObjCRuntime.ObjCException

  •   An unhandled exception of type 'ObjCRuntime.ObjCException' occurred in Microsoft.iOS.dll    at UIKit.UIApplication.xamarin_UIApplicationMain(Int32 argc, IntPtr argv, IntPtr principalClassName, IntPtr delegateClassName, IntPtr* gchandle)   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)   at Inventiva.Program.Main(String[] args) in /Users/sreejith.sreenivasan/Downloads/inv-hnas337-mobile-patient/Inventiva/Platforms/iOS/Program.cs:line 13

While analyzing the logs I didn't see anything unusual.

Developer technologies | .NET | .NET MAUI

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-04-09T10:13:39.2566667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    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/finally blocks, 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/@catch block. When an NSException is caught, it is converted to a managed exception and rethrown as ObjCRuntime.ObjCException in managed code.
    • On the main thread, UIApplicationMain itself is typically wrapped in an Objective‑C @try/@catch that 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 as ObjCException.

    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:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.