Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to marshal the Objective-C object #68

Open
scarabdesign opened this issue Oct 7, 2021 · 0 comments
Open

Failed to marshal the Objective-C object #68

scarabdesign opened this issue Oct 7, 2021 · 0 comments

Comments

@scarabdesign
Copy link

Visual Studio Enterprise 2019 for Windows
C# 9.0
Xamarin iOS 15.0.0.8
Windows 10 / macOS 11.6
iPhone with iOS 15 (a few different models)

My iOS app is returning this error from time to time since iOS 15.

Failed to marshal the Objective-C object 0x283f57080 (type: Square_SocketRocket_WebSocket__WebSocketDelegate). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Square.SocketRocket.WebSocket+_WebSocketDelegate' does not have a constructor that takes one IntPtr argument).
Additional information:
	Selector: webSocket:didCloseWithCode:reason:wasClean:
	Method: Square.SocketRocket.WebSocket/_WebSocketDelegate:WebSocketClosed (Square.SocketRocket.WebSocket,Square.SocketRocket.StatusCode,string,bool)
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x1045076f0 + 0x0005f> in <e6d97443f5714185be8a5ae6def186ed#b54e071fd57ec77c1c927dfc03ab3584>:0 
  at ERPXamarin.iOS.Application.Main (System.String[] args) <0x102f89660 + 0x00023> in <f1aa27121c6a43c1b9012db9d8bcee83#b54e071fd57ec77c1c927dfc03ab3584>:0 

My app seems to catch and report the error to me (in a managed way) and recover from it by trying again, but it seems to always present the user with the option to send a bug report to Apple, which I'm not fond of.

I'm catching the error from an event listener in the AppDelegate.cs:

        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            Runtime.MarshalObjectiveCException += Runtime_MarshalObjectiveCException;
            [...]
        }
            
        private void Runtime_MarshalObjectiveCException(object sender, MarshalObjectiveCExceptionEventArgs args)
        {
            args.ExceptionMode = MarshalObjectiveCExceptionMode.ThrowManagedException;
            if (args.Exception == null || args.Exception.CallStackSymbols == null) return;
            Logger.LogError("AppDelegate.Runtime_MarshalObjectiveCException: " + args.Exception.CallStackSymbols.Aggregate((s1, s2) => s1 + "\r\n" + s2));
        }
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

No branches or pull requests

1 participant