Type Provider hangs app when loading data from localhost

99封情书 提交于 2019-12-11 05:28:23

问题


I have reason to believe that the type provider that I'm using is hanging my app that's running 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

来源:https://stackoverflow.com/questions/41700086/type-provider-hangs-app-when-loading-data-from-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!