Bug 33720 - AppDelegate.FinishedLaunching - "Cannot cast from source type to destination type"
Summary: AppDelegate.FinishedLaunching - "Cannot cast from source type to destination...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.4.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-09-05 19:06 UTC by manuel
Modified: 2015-09-05 21:12 UTC (History)
1 user (show)

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

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 manuel 2015-09-05 19:06:07 UTC
Again a cast issue. This time was a cause of a valid app store rejection...

What is happening and an important note before going into more details. With last version available on stable channel we did not have this issue happening.

# Launching the app from TestFlight

It crashed at launching in all tests that we did with a 6 (ios 8.4.1) with the build that we submitted and that was rejected. Stupidly we just did this tests after receiving a rejection... lesson learned! :) The logs that we have from Apple's tests showed that they used  iPad5,4
We did not do yet any test with 32 bit devices. For now we can say it is happening at least in 64 bit devices.

Error Stack trace:

Device = iPhone7,2; 
App Version = 1.1.0; 
Build = 234; 
System Version = 8.4.1; 
Error = System.InvalidCastException: Cannot cast from source type to destination type. at Storyo.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00000] in <filename unknown>:0 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0 at Storyo.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0 

Inside FinishedLaunching we have the following candidates to have something like this happening:

window = new UIWindow (UIScreen.MainScreen.Bounds);
RootNavigationController = new UINavigationController ();

//One of our controllers
StartScreen = new MyStoriesViewController (DataBaseManager.IsFirstTimeUsingApp ());

//A C# method 
StartScreen.WillEnterForeground ();

Note OurViewController : UIViewController

MyStoriesViewController : OurViewController


public virtual void WillEnterForeground()



public override void WillEnterForeground()

Launching the app normally from its icon
It seems it is always working. At least in the following physical devices where we did (a lot of) tests with a "release" profile 

iphone 6 (ios 8.4.1), 6+ (ios 9 beta 4), 5 (ios 8.4.1), 4s (ios 8.4.1) and iPad 3 (ios 8.4.1) 

and on simulator

iphone 4 (ios 7)  


##Release and AppStore

Supported Architectures - ARMv7 and ARM64
GC = SGen

##Framework and IDE versions

Xamarin Studio
Version 5.9.5 (build 10)
Installation UUID: 5f421f3f-40c4-4caa-8ae3-df7a8094edf4
	Mono 4.0.3 ((detached/d6946b4)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400030020

Apple Developer Tools
Xcode 6.4 (7720)
Build 6E35b

Version: (Business Edition)
Hash: 2c66d2f
Branch: master
Build date: 2015-08-04 13:52:25-0400

Version: (Business Edition)
Android SDK: /Users/nativolabs/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

Xamarin Android Player
Version: Unknown version
Location: /Applications/Xamarin Android Player.app

Not Installed

Build Information
Release ID: 509050010
Git revision: 48d16bc4f12ce3938964fc7c3d72fdc6887ad4ad
Build date: 2015-08-18 16:55:24-04
Xamarin addins: c2d51b360ad9f59e689046d47030df27de28f94a

Operating System
Mac OS X 10.10.5
Darwin Nativos-MBP.home 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 1 manuel 2015-09-05 19:17:53 UTC
Just 1 more information

Build that was working before was this


used to solve this bug

Comment 2 manuel 2015-09-05 21:12:16 UTC
Forget it! 
This was an error handling options sent in FinishedLaunching. Probably the values sent changed and were not handling correctly and ended up doing an invalid cast.