Bug 8457 - Misleading error message when forgetting to decorate constructor with [Export("initWithFrame:")]
Summary: Misleading error message when forgetting to decorate constructor with [Export...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.0.x
Hardware: PC Mac OS
: --- enhancement
Target Milestone: Untriaged
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2012-11-16 06:26 UTC by Dan Abramov
Modified: 2014-03-03 09:02 UTC (History)
2 users (show)

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


Attachments
MonoDevelop obscures inner exception which is the real issue (241.98 KB, image/png)
2012-11-16 06:27 UTC, Dan Abramov
Details


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:
Status:
RESOLVED FIXED

Description Dan Abramov 2012-11-16 06:26:44 UTC
I'm learning to use UICollectionView, and my app would crash with this exception when calling DequeueReusableCell:

“Selector invoked from objective-c on a managed object of type App.TestCell (0xC65FFA0) that has been GC'ed”

I later learned that I forgot to decorate the cell constructor with [Export]:

[Export ("initWithFrame:")]
public TestCell (RectangleF frame) : base (frame)

In fact, the inner exception clearly shows this was the problem:

[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Selector invoked from objective-c on a managed object of type App.TestCell (0x1A7D8160) that has been GC'ed ---> System.MissingMethodException: No constructor found for App.TestCell::.ctor(System.IntPtr)
  at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x000f1] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:280 

Still, I think the actual exception being thrown is confusing and misleading.
The problem is supposed to be with the missing method and NOT with GC.

Is there any way to throw a more user-friendly exception?
Attached is the error I saw (as you can see, you need to _scroll_ to see the inner exception).
Comment 1 Dan Abramov 2012-11-16 06:27:26 UTC
Created attachment 2955 [details]
MonoDevelop obscures inner exception which is the real issue
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-11-16 20:16:15 UTC
This is a complicated error condition to give good information about, historically the current message has been right most of the time (and thus helpful to whoever ran into it, a lot more than what a MissingMethodException would be), but then there are people like you, who run into it because of other bugs in your code, in which case the error message is just plain wrong.

The good knews is that we've done work to eliminate the first case (where the error message was useful) - this is currently being tested in the 6.0.6 (beta) release. Hopefully this means that we can give a better message for your case soon.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-03-03 09:02:19 UTC
This error message was improved some time ago.