Bug 4414 - Subclassing UIView and overriding BackgroundColor crashes on device but not simulator.
Summary: Subclassing UIView and overriding BackgroundColor crashes on device but not s...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-04-12 17:59 UTC by mgreger
Modified: 2012-04-12 20:19 UTC (History)
2 users (show)

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


Attachments
Subclass example (386 bytes, application/octet-stream)
2012-04-12 17:59 UTC, mgreger
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 mgreger 2012-04-12 17:59:23 UTC
Created attachment 1663 [details]
Subclass example

Create a new single view iPhone project. Create a class that derives from UIView, mark it with the Register attribute, create a constructor which takes an IntPtr, and override the BackgroundColor property. Open the iPhone view in interface builder and change the view to use the custom subclass. The resulting application will run fine on the simulator, but crash on a real iPhone or iPod touch (tested on iOS 4 and 5). This behavior does not seem to happen if a xib file is not used and the view is created programmatically.

Mono: 2.10.9 
MonoDevelop 2.8.8.4 
Monotouch: 5.2.10 
Mac OS X 10.7.3
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-04-12 18:21:45 UTC
I can reproduce this, looking at it now.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-04-12 20:19:32 UTC
Fixed in master (364b2ce2) and 5.2-series (ca3faa42); unit tests added too. The next releases with this fix will be 5.2.12 and 5.3.3.

In the meantime I believe you can use this workaround in your custom view:

[Export ("backgroundColor", ArgumentSemantic.Retain)]
public new UIColor BackgroundColor {
   get { return base.BackgroundColor; }
   set { base.BackgroundColor = value; }
}