F# Xamarin.Mac Project throws NullReferenceException after start

I have created new F# Xamarin.Mac Project (using trial Xamarin.Mac license), and have several problems:

  1. After building and running it right away throws NullReferenceException in AppDelegate.fs for property Window in line:
  2. It does not generates h and m files for MainWindowController, so I need to make them manually in Xcode.
  3. After creating design in Xcode and returning to Xamarin Studio, it generates MainWindowController.Designer.cs, which goes after AppDelegate.fs, which causes compiler error on [] attribute (which should be in the last file in project).
  4. And it has second compiler problem - it cannot find property Window in MainWindowController type (in the same code line as in point 1), probably can't handle properly partial types from MainWindowController.fs and MainWindowController.Designer.fs.

Could you please confirm if F# does really works with Xamarin.Mac with UI, or it only works with library projects?


  • FabioGFabioG ITBeta, University ✭✭✭

    @Ravlyk, F# support for Xamarin.Mac is a bit of a mess at the moment.
    1. looks like a bug of the template to me, if you create a project form the template it should compile and run just fine. You could report the issue at https://github.com/fsharp/fsharpbinding.
    I managed to make storyboards work with Xamarin.iOS but I had to define all the outlets and actions by hand. Automatic generation of code behind is not supported. Xamarin Studio cannot generate Designer.fs files because F# lacks partial classes. If it generated Designer.cs files instead, it was a bug too.
    If you're an adventurous one, you can try building all your UI in code or adding outlets and actions by hand. Otherwise may be it's better to stick to C# for UI development.
    A lot of work needs to be done to make everything run properly with C# and F# especially with all the newer stuff (like Xamarin Unified API and Apple's Storyboard support for Mac OS X).

  • Ok, I see.
    Regarding designer part of UI in F# - it could be done without partial classes - just one extra inheritance level:
    BaseWindowClass -> MyWindowDesignClass -> MyWindowClass

  • FabioGFabioG ITBeta, University ✭✭✭
    edited October 2014

    That's interesting...

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Thanks for the reports guys. I believe we've had some of these fixed internally and somehow the stale templates got released. I'm going to file a bug (and report it here) to have the F# guy take a look once the bugzilla comes back up from the CVE.

  • Emil.7939Emil.7939 USMember
    edited November 2014

    I can confirm that this issue is still present. Just now downloaded Xamarin Studio, tried creating F# solutions for Mac or iOS, open-source and otherwise, they all crash with a System.NullReferenceException on the mainWindowController.Window property.

    I'm wondering why this was even released?


  • DaveThomasDaveThomas GBMember, Xamarin Team Xamurai

    In the template theres a missing constructor overload for the MainWindowController:

    new() = { inherit NSWindowController ("MainWindow") }

    Actually to make it clear heres the full type:

    [<Register("MainWindowController")>] type MainWindowController = inherit NSWindowController new() = { inherit NSWindowController ("MainWindow") } new(handle : IntPtr) = { inherit NSWindowController (handle) } [<Export ("initWithCoder:")>] new(coder : NSCoder) = { inherit NSWindowController (coder) }

    Previously the API must have automatically supplied the "MainWindow". Theres no specific designer support on Mac and no unified templates for it, so at the moment your limited to hand cranking your UI properties etc.

Sign In or Register to comment.