Bug 14354 - Failed to marshal the Objective-C object
Summary: Failed to marshal the Objective-C object
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.3.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-08-30 16:34 UTC by Allie Miller
Modified: 2013-09-03 17:34 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Crash report device log from my phone when it occurred again after filing this report (34.50 KB, application/octet-stream)
2013-08-30 16:44 UTC, Tommy Baggett
Video of test workflow (3.12 MB, video/mp4)
2013-08-30 16:59 UTC, Tommy Baggett

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Allie Miller 2013-08-30 16:34:43 UTC
This error appeared when tapping a button, although there is no in-app code for handling the button touch. I set up the button touch handling visually by creating a segue in the storyboard using the XCode storyboard editor. This was done by  Option-clicking the button in XCode, then dragging to the view controller that segued a transition to occur with.

2013-08-29 19:25:14.559 XNotesiOS[19348:907] Unhandled Exception: Failed to
marshal the Objective-C object 0x21be9290 (type:
MonoTouch.UIKit.UIGestureRecognizer+_UIGestureRecognizerDelegate). Could
not find an existing managed instance for this object, nor was it possible
to create a new managed instance (because the type
'MonoTouch.UIKit.UIGestureRecognizer+_UIGestureRecognizerDelegate' does not
have a constructor that takes one IntPtr argument).

Unable to provide a test case that consistently reproduces the issue since the UIGestureRecognizerDelegate error has only been displayed once.  

Version Information:
Xamarin Studio
Version 4.0.12 (build 3)
Installation UUID: 5c4c653a-6321-4998-a882-b71b1e1a4005
Mono 3.2.0 ((no/7c7fcc7)
GTK 2.24.20
GTK# (
Package version: 302000000

Apple Developer Tools
Xcode 4.6.3 (2068)
Build 4H1503

Xamarin.Mac: 1.4.8

Version: 4.8.1 (Business Edition)
Android SDK:
Supported Android versions:
1.6 (API level 4)
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
3.2 (API level 13)
4.0 (API level 14)
4.0.3 (API level 15)
4.1 (API level 16)
4.2 (API level 17)
Java SDK: /usr
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)

Version: (Business Edition)
Hash: 0068990
Build date: 2013-13-08 05:24:39-0400

Build Information
Release ID: 400120003
Git revision: 593d7acb1cb78ceeeb482d5133cf1fe514467e39
Build date: 2013-08-07 20:30:53+0000
Xamarin addins: 25a0858b281923e666b09259ad4746b774e0a873

Operating System
Mac OS X 10.8.4
Darwin um-mbp 12.4.0 Darwin Kernel Version 12.4.0
Wed May 1 17:57:12 PDT 2013
root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64
Comment 2 Tommy Baggett 2013-08-30 16:44:17 UTC
Created attachment 4765 [details]
Crash report device log from my phone when it occurred again after filing this report

This issue occurs repeatedly in my app as I am stress-testing it.  I can go through a workflow 3 times before tapping the button causes this crash.
Comment 3 Tommy Baggett 2013-08-30 16:59:13 UTC
Created attachment 4766 [details]
Video of test workflow

App crashes consistently on starting the third round of the workflow by tapping the "Create XNote" button.
Comment 4 Tommy Baggett 2013-08-30 17:01:39 UTC
One clarification:  The crash occurs consistently.  I have only seen the message in the XS console output regarding the missing constructor with an IntPtr argument one time.
Comment 5 Tommy Baggett 2013-08-31 04:16:49 UTC
I have determined this issue and the other random crashes I've been seeing only occur if the SGen GC is being used.  I switched my project back to the Boehm GC and no errors are occurring, even if I proceed through the same workflow 20 times.  I also monitored overall memory consumption and leaks using the XCode Instruments profiler and see things being released as expected.
Comment 6 Sebastien Pouliot 2013-09-03 09:24:45 UTC
Such issues are, 99% of the time, related to a managed instance with no reference. At some point the GC will collect it and it will crash whenever some native code tries to callback into the (now freed) managed instance.

> The crash occurs consistently. 

Please provide a self-contained test case (the smaller the better) and we'll look into it.
Comment 7 Tommy Baggett 2013-09-03 14:35:13 UTC
Hi Sebastien,

Thanks for the response.  The crash occurs consistently in my app, being that it was always happening on the beginning of the third round of the workflow.  Creating a small self-contained test case may not be so easy.  You can watch the attached video to see the flow if you're interested.

Fortunately, I did determine the source of the problem.  I was creating a UITapGestureRecognizer when the keyboard became visible so I could detect the user tapping outside of the edit field and dismiss the keyboard.  I was properly releasing the recognizer if the the user tapped outside the edit field or otherwise dismissed the keyboard.  However, I was only setting the property to null in my Dispose method, instead of first calling View.RemoveGestureRecognizer().  So, my case falls into the 99% as you say. :-)
Comment 8 Sebastien Pouliot 2013-09-03 17:34:41 UTC
Glad you got it to work :)