Following this guide https://blog.xamarin.com/preview-bringing-macos-to-xamarin-forms/ I created a MacOS assembly to run my Xamarin.Forms app in this platform. But trying to run the result gives a NullReferenceException, see below.
锘縩amespace GWallet.Frontend.XamForms.Mac
open System
open Foundation
open AppKit
open Xamarin.Forms
open Xamarin.Forms.Platform.MacOS
[<Register ("AppDelegate")>]
type AppDelegate () =
inherit FormsApplicationDelegate ()
let style = NSWindowStyle.Closable ||| NSWindowStyle.Resizable ||| NSWindowStyle.Titled
let rect = new CoreGraphics.CGRect(200.0f, 1000.0f, 1024.0f, 768.0f)
let window = new NSWindow(rect, style, NSBackingStore.Buffered, false)
do
window.Title <- "Xamarin.Forms on Mac!"
window.TitleVisibility <- NSWindowTitleVisibility.Hidden
override this.MainWindow
with get() = window
override this.DidFinishLaunching(notification: NSNotification) =
Forms.Init()
this.LoadApplication(new GWallet.Frontend.XF.App())
// FIXME: the line below reports an NRE which prevents launch
base.DidFinishLaunching(notification)
(My app is opensource, so for reference this is the full commit: https://github.com/knocte/gwallet/commit/448fb0e0135ca50097e8e4a1faacbf46c49d38b7.diff
Should run, no exceptions.
Boom:
System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate.UpdateMainMenu () [0x00021] in <7e711cd2aa53409881089d77021878ae>:0
at Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate.DidFinishLaunching (Foundation.NSNotification notification) [0x00047] in <7e711cd2aa53409881089d77021878ae>:0
at GWallet.Frontend.XamForms.Mac.AppDelegate.DidFinishLaunching (Foundation.NSNotification notification) [0x00011] in /Users/andres/Documents/Code/gwalletFRONTEND/src/GWallet.Frontend.XamForms.Mac/AppDelegate.fs:28
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/5489/1bda16aa/source/xamarin-macios/src/AppKit/NSApplication.cs:100
at GWallet.Frontend.XamForms.Mac.main.main (System.String[] args) [0x00015] in /Users/andres/Documents/Code/gwalletFRONTEND/src/GWallet.Frontend.XamForms.Mac/Main.fs:10
2018-01-25 01:56:43.729 GWallet[96223:55394509] warning: exception inside UnhandledException handler: Object reference not set to an instance of an object
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate.UpdateMainMenu () [0x00021] in <7e711cd2aa53409881089d77021878ae>:0
at Xamarin.Forms.Platform.MacOS.FormsApplicationDelegate.DidFinishLaunching (Foundation.NSNotification notification) [0x00047] in <7e711cd2aa53409881089d77021878ae>:0
at GWallet.Frontend.XamForms.Mac.AppDelegate.DidFinishLaunching (Foundation.NSNotification notification) [0x00011] in /Users/andres/Documents/Code/gwalletFRONTEND/src/GWallet.Frontend.XamForms.Mac/AppDelegate.fs:28
--- End of stack trace from previous location where exception was thrown ---
at GWallet.Backend.Infrastructure.Report[a] (System.Exception ex) [0x0000c] in /Users/andres/Documents/Code/gwalletFRONTEND/src/GWallet.Backend/Infrastructure.fs:19
at GWallet.Backend.Infrastructure.OnUnhandledException[a] (System.Object sender, System.UnhandledExceptionEventArgs args) [0x00000] in /Users/andres/Documents/Code/gwalletFRONTEND/src/GWallet.Backend/Infrastructure.fs:25
at [email protected] (System.Object sender, System.UnhandledExceptionEventArgs e) [0x00000] in /Users/andres/Documents/Code/gwalletFRONTEND/src/GWallet.Backend/Infrastructure.fs:28
I observed the same behavior this morning. I found a better guide in the docs.
The blog could be behind or it could be a bug. The difference is that the blog instructs the user to remove the storyboard. I am guessing that you need to keep it.
Yeah this was a change @bholmes we actually needed the storyboard when we add Menu support. @davidortinau can we make sure we update the blog with this info.
@rmarinho oh, but I thought this might have been fixed by https://github.com/xamarin/Xamarin.Forms/commit/f0022e1361c997d6e40ffd7b88bdc1cfa7b2e0ee ?
I guess I could verify this by using MyGet+nightlies, but I was wondering, why don't you guys publish a 2.6 pre-release on nuget.org?
@knocte that would prevent also yeah, but if using Menus we now recommend just leave the Storyboard. About 2.6 we are not ready for that release yet. Still working on some features with the community. We also need more testing so make sure you give it a try.
This is fixed on nightly and next release
This is fixed on nightly and next release
Hey Rui, by next release you mean 2.5.0.280555 which was uploaded to Nuget.org 5 days ago?
@knocte I think he means the next major or minor release. 2.5.0.280555 was just a service release for 2.5.
yeah thanks @hartez , @knocte it will be in the next pre release we ship.
@rmarinho : just saw a new pre-release posted in nuget: 2.5.1.317207-pre1 , is it this one, or will it be a 2.6.x or 3.x one?
Yeah not this one, 3.0 one
@davidortinau The blog post still instructs people to remove the NSMainStoryboardFile entry from Info.plist and that causes the Mac project to not run. I just tried with Stable 2.5.0.280555 and was able to reproduce the issue. But following the docs link above it works like a charm :)