Type Provider hangs app when loading data from localhost

ScottNimrodScottNimrod USMember ✭✭
edited January 2017 in Xamarin.Android

I have reason to believe that the type provider that I'm using is hanging my app on the Android emulator.

On my main page within a Xamarin.Forms app, I have the following load operation:

protected override void OnAppearing()
{
    _viewModel.Load();
    return; // Never gets reached when using Type Provider...
}

My viewmodel has the following load operation:

public void Load() => Cars = new ObservableCollection<Car>(getCars());

My F# code is the following:

open FSharp.Data

// https://forums.xamarin.com/discussion/1199/how-to-make-our-remote-host-127-0-0-1-reachable-from-android-device-monoandroid-using-vs2010
[<Literal>]      (* "10.0.2.2" is the workaround IP address for local host *)
let JsonPathDesignTime = "http://localhost:48213/api/cars"
let JsonPathRunTime =    "http://10.0.2.2:48213/api/cars"
type Repository =         JsonProvider<JsonPathDesignTime>

type Car = { Make:string ; Model:string }

let getCars() =

    try
        Repository.Load JsonPathRunTime
        |> Array.toSeq
        |> Seq.map(fun x -> { Make=x.Make ; Model=x.Model })

    with error -> failwith error.Message

I did not observe any exceptions thrown with the code above. However, return to the client caller does NOT occur.

NOTE:

If I don't use a Type Provider, but instead return an empty sequence, then the app does NOT hang.

Example:

type Car = { Make:string ; Model:string }

let getCars() : Car seq =
    Seq.empty
Sign In or Register to comment.