Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 14759 [details]
Code to reproduce the bug
Open the attached project, you'll find the following code:
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
// Override point for customization after application launch.
// If not required for your application you can safely delete this method
var p = new PlayerViewController ();
var v = p.View;
public PlayerViewController () : base ("PlayerViewController", null)
Console.WriteLine ("PlayerViewController () called.");
Run the project and check the log, you'll see this last line twice.
The first call is correct, the second call is invoked by the line calling View.
It seems that when iOS detects a class with the same name as a xib, in some cases it tries to do some magic, which causes a new instance of the class to be created.
The same thing happens in Xcode with a Objective-C sample: https://github.com/rolfbjarne/bug38109, so this is not a bug in Xamarin.iOS.
I see. Please report it to Apple then. Also, do you think there's a workaround short of not using a xib at all?
You can add a dummy argument to the default ctor:
public PlayerViewController (bool dummy = false)
and it won't be called by iOS.
It works, thank you.