Bug 20957 - F# iOS "Empty Project" templates produce runtime error
Summary: F# iOS "Empty Project" templates produce runtime error
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: F# Add-in ()
Version: unspecified
Hardware: PC Mac OS
: Normal normal
Target Milestone: master
Assignee: Dave Thomas
URL:
Depends on:
Blocks:
 
Reported: 2014-06-27 15:33 UTC by Larry O'Brien
Modified: 2014-07-03 08:41 UTC (History)
4 users (show)

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


Attachments
Generates runtime *** Assertion failure in -[UIApplication applicationWillOrderInContext:forWindow:], /SourceCache/UIKit_Sim/UIKit-3232.3/UIApplication.m:10072 (831 bytes, application/octet-stream)
2014-06-27 15:33 UTC, Larry O'Brien
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 Larry O'Brien 2014-06-27 15:33:02 UTC
Created attachment 7224 [details]
Generates runtime  *** Assertion failure in -[UIApplication applicationWillOrderInContext:forWindow:], /SourceCache/UIKit_Sim/UIKit-3232.3/UIApplication.m:10072

When you choose "New Solution/F#/iOS/[iPhone|iPad|Universal]/Empty Project" the generated template attempts to instantiate the UIWindow prior to FinishedLaunching. This causes a runtime exception when you define a UIViewController and attempt to assign it's View.

Existing:

    let window = new UIWindow (UIScreen.MainScreen.Bounds)

    // This method is invoked when the application is ready to run.
    override this.FinishedLaunching (app, options) =
        // If you have defined a root view controller, set it here:
        // window.RootViewController <- new MyViewController ()
        window.MakeKeyAndVisible ()
        true


Should be:

    // This method is invoked when the application is ready to run.
    override this.FinishedLaunching (app, options) =
        let window = new UIWindow (UIScreen.MainScreen.Bounds)

        // If you have defined a root view controller, set it here:
        // window.RootViewController <- new MyViewController ()
        window.MakeKeyAndVisible ()
        true
Comment 1 Larry O'Brien 2014-06-27 17:19:16 UTC
Grrr... My "Should Be" is still wrong since `window` can be collected. 

This works:

type AppDelegate () =
    inherit UIApplicationDelegate ()

    override val Window : UIWindow = null with get, set

    // This method is invoked when the application is ready to run.
    override this.FinishedLaunching (app, options) =
        this.Window <- new UIWindow (UIScreen.MainScreen.Bounds)

        // If you have defined a root view controller, set it here:
        this.Window.RootViewController <- new MyViewController ()
        this.Window.MakeKeyAndVisible ()
        true
Comment 2 Fabio Garagiola 2014-07-03 04:49:19 UTC
Same problem here. I'm on the Alpha Channel.

Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: must have a non-nil scene

Application Output: *** Assertion failure in -[UIApplication applicationWillOrderInContext:forWindow:], /SourceCache/UIKit_Sim/UIKit-3232.3/UIApplication.m:10072

Xamarin Studio: Version 5.1.1 (build 19)
Apple Developer Tools: Xcode 6.0 (6194.24) Build 6A216f
Xamarin.iOS Version: 7.9.1.90 (Business Edition)
Operating System: Mac OS X 10.9.4
Mono: 3.6.0

F# Language Binding: Version 5.0.3
Comment 3 Fabio Garagiola 2014-07-03 05:46:36 UTC
I forgot to mention that is a regression because it does work on the Stable Channel.

The solution proposed by Larry O'Brien:

 override val Window : UIWindow = null with get, set

should be considered a workaroud now but, once the bug is fixed, could replace the current let binding in template:

 let window = new UIWindow (UIScreen.MainScreen.Bounds)

because it makes it easier to use a storyboard in the project out of the box.
Comment 4 Dave Thomas 2014-07-03 08:16:54 UTC
Fabio, The bug is the wrong instantiate order in the template, I will amend the template.
Comment 5 Dave Thomas 2014-07-03 08:41:04 UTC
Fixed in FSharpbinding master