F#: Loading images from files causes a null reference exception

1. Create a new project, of type "Visual F# -> Android -> Blank App (Android)"

2. Add the Xamarin.Forms Nuget package.

3. Replace the code in MainActivity.fs with

namespace <<MyProjectName>>

open System

open Xamarin.Forms.Platform.Android

open Android.App
open Android.Content
open Android.OS
open Android.Runtime
open Android.Views
open Android.Widget

type MainPage() =

    inherit Xamarin.Forms.ContentPage()
    let layout = new Xamarin.Forms.StackLayout()
    do layout.Children.Add(new Xamarin.Forms.Button(Image = new Xamarin.Forms.FileImageSource(File = "Icon.jpg")))
    do base.Content <- layout

type App() =

    inherit Xamarin.Forms.Application()
    do base.MainPage <- new MainPage()

[<Activity (Label = "FSharpResourcesDemo", MainLauncher = true)>]
type MainActivity () =

    inherit FormsApplicationActivity()
    override this.OnCreate (bundle) =
        base.OnCreate (bundle)
        Xamarin.Forms.Forms.Init(this, bundle)
        this.LoadApplication(new App())

Run the app.


Note that ImageSource.FromFile() breaks in exactly the same way.

Reference: https://bugzilla.xamarin.com/show_bug.cgi?id=53515