Bug 24824 - [XF 1.3-Pre, all platforms] "Can not create more than one Application instance"
Summary: [XF 1.3-Pre, all platforms] "Can not create more than one Application instance"
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: PC All
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-11-25 19:53 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-01-23 09:48 UTC (History)
8 users (show)

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


Attachments
Test case (88.41 KB, application/zip)
2014-11-25 19:53 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2014-11-25 19:53:41 UTC
Created attachment 8870 [details]
Test case

[XF 1.3-Pre, all platforms] "Can not create more than one Application instance"

Regression status: regression between 1.2.3.6257 and 1.3.0.6275-pre1


## Steps to reproduce

Build and run the attached test case on an iOS, Android, or Windows Phone device or emulator (tested on iPhone 5s, iOS 8.1 simulator, Android 4.1.2 device, and Windows Phone emulator).

The test case is the Xamarin.Forms PCL template project with just a few small changes. The core of the problem is the following two lines in the `AppDelegate.FinishedLaunching()` method for iOS:

> App.GetSecondPage().CreateViewController();
> window.RootViewController = App.GetMainPage().CreateViewController();

... the two similar lines in the `MainActivity.OnCreate()` method for Android:
> SetPage(App.GetSecondPage());
> SetPage(App.GetMainPage());

... and the two similar lines in `MainPage.MainPage()` for Windows Phone:
> FormsApp1.App.GetSecondPage().ConvertPageToUIElement(this);
> Content = FormsApp1.App.GetMainPage().ConvertPageToUIElement(this);


## Result

### iOS

> Unhandled managed exception: Can not create more than one Application instance. (System.InvalidOperationException)
>   at Xamarin.Forms.Application.set_Current (Xamarin.Forms.Application value) [0x00000] in <filename unknown>:0 
>   at Xamarin.Forms.Application..ctor () [0x00000] in <filename unknown>:0 
>   at Xamarin.Forms.PageExtensions+DefaultApplication..ctor (Xamarin.Forms.Page mainPage) [0x00000] in <filename unknown>:0 
>   at Xamarin.Forms.PageExtensions.CreateViewController (Xamarin.Forms.Page view) [0x00000] in <filename unknown>:0 
>   at FormsApp1.iOS.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00027] in c:\Users\Windows User\Desktop\FormsApp1\FormsApp1\FormsApp1.iOS\AppDelegate.cs:36 
>   at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
>   at MonoTouch.UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr dele
> gate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62 
>   at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46 
>   at FormsApp1.iOS.Application.Main (System.String[] args) [0x00001] in c:\Users\Windows User\Desktop\FormsApp1\FormsApp1\FormsApp1.iOS\Main.cs:17 

### Android

> Unhandled Exception:
> System.InvalidOperationException: Can not create more than one Application instance.
>   at Xamarin.Forms.Application.set_Current (Xamarin.Forms.Application value) [0x00000] in <filename unknown>:0 
>   at Xamarin.Forms.Application..ctor () [0x00000] in <filename unknown>:0 
>   at Xamarin.Forms.Platform.Android.FormsApplicationActivity+DefaultApplication..ctor (Xamarin.Forms.Page mainPage) [0x00000] in <filename unknown>:0 
>   at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetPage (Xamarin.Forms.Page page) [0x00000] in <filename unknown>:0 
>   at FormsApp1.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0001d] in c:\Users\Windows User\Desktop\FormsApp1\FormsApp1\FormsApp1.Android\MainActivity.cs:24 
>   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.Activity.cs:2179 
>   at (wrapper dynamic-method) object:0d74abcc-e58e-4eef-9a5a-e4c1d463d1ac (intptr,intptr,intptr)


## Version information

Xamarin.Forms 1.3.0.6275-pre1

Xamarin   3.8.150.0 (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Xamarin.Android   4.20.0.28 (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Xamarin.iOS   8.4.0.0 (840a925103a0bf4a856507f13d5eaee3c1579c2f)

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

NuGet Package Manager   2.8.50926.663
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2014-11-25 23:08:39 UTC
From a bit more reading, it appears that the `SetPage()` and `CreateViewController()` methods are deprecated in favor of `LoadApplication()` starting in XF 1.3.0.

> [1] http://www.infinite-x.net/2014/10/09/xamarin-forms-1-3-0-preview-formapplication/
> [2] http://forums.xamarin.com/discussion/comment/80851/#Comment_80851


Another forum comment [3] raises the question of interoperating with native views as in [4] and [5]. Perhaps this is intentionally no longer supported in Xamarin.Forms 1.3.0?

> [3] http://forums.xamarin.com/discussion/comment/89242/#Comment_89242

> [4] https://github.com/xamarin/xamarin-forms-samples/tree/master/Native2Forms
> [5] https://github.com/xamarin/xamarin-forms-samples/tree/master/Forms2Native


In short, this "regression" might be intentional.
Comment 3 tim.ahrentlov 2014-11-26 09:58:44 UTC
Could we get some Xamarin developer insights on this ?

Will Native2Forms and Forms2Native be supported going forward?
Comment 4 Sadik Ali 2015-01-02 04:29:05 UTC
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the steps and instruction provided in bug description.

Steps I followed:

1. Open attached test case in XS.
2. Set android as startup project, build and deploy on emulator.
3. Observed that following exception:
"System.InvalidOperationException: Can not create more than one Application instance."
4. Set iOS as startup project, build and deploy on simulator.
3. Observed that following exception:
"System.InvalidOperationException: Can not create more than one Application instance."

Here is the screencast for the same: http://www.screencast.com/t/N7sAZgCGnD

===Supplement Info For Android===

Exception details: https://gist.github.com/Sadik1/e40deafe59364dbf2f05
Application Output: https://gist.github.com/Sadik1/7df06bacd33e70c708a8
Build Output: https://gist.github.com/Sadik1/688b98459ba4dfdb9992

===Supplement Info For iOS===
Exception details: https://gist.github.com/Sadik1/e3612e8190ed9d03c0b4
Application output: https://gist.github.com/Sadik1/4534a6edd6e2285c2458
Build Output: https://gist.github.com/Sadik1/045850ea0f13df6eb92a

XS Logs: http://www.screencast.com/t/nbcn6LxNb14

Environment Info:

Xamarin.Forms 1.3.0.6275-pre1

=== Xamarin Studio ===
Version 5.5.4 (build 15)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		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)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: 8.4.0.47 (Business Edition)
Hash: 7244769
Branch: 
Build date: 2014-12-11 14:54:30-0500

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 5 Eric Maupin 2015-01-14 14:16:15 UTC
Fixed for 1.3.2-pre1
Comment 6 Dawid Morzyński 2015-01-16 09:52:09 UTC
When will be posted updated version?
Comment 7 Sunil Kumar 2015-01-23 09:48:50 UTC
I have checked this issue with Xamarin.Forms 1.3.2.6299- pre1 package and now it's working fine with this. Attached project is build/run successfully with Xamarin.Forms 1.3.2.6299- pre1 without any exception.

Screencast: http://www.screencast.com/t/aP7m1DsIP

Environment Info:

Xamarin.Forms 1.3.2.6299- pre1

=== Xamarin Studio ===

Version 5.7.1 (build 14)
Installation UUID: 561c7a69-0a91-4bae-ad7c-f0c79d594337
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 8.6.1.19 (Trial Edition)
Hash: 80971a6
Branch: 
Build date: 2015-01-21 17:42:51-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Trial Edition)
Android SDK: /Users/tajinder/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.12.0.4 (Starter Edition)

=== Build Information ===

Release ID: 507010014
Git revision: a4dd61ad7f8b3695be4b17bcb5c3ae6b81438cf7
Build date: 2015-01-19 15:21:09-05
Xamarin addins: 081208fe3bbf40e24a562867c6c7fba20a9b94b6

=== Operating System ===

Mac OS X 10.8.4
Darwin Tajinders-iMac.local 12.4.2 Darwin Kernel Version 12.4.2
    Mon Jun 17 18:00:12 PDT 2013
    root:xnu-2050.45.8~1/RELEASE_X86_64 x86_64