Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

I am unable to use a Type Provider on a localhost for an Android Emulator

I am unable to use a Type Provider on a localhost for an Android Emulator.

This doesn't work for me when using F#'s Type Provider because the TypeProvider establishes a connection at design-time.

The Type Provider is happy when I use localhost

[<Literal>]
let JsonPath =   "http://localhost:48213/api/cars"
type Repository = JsonProvider<JsonPath>

However, I receive a connection refused when attempting to use the localhost path. Details about this error can be found here.

As a result, I believe the resolution is to use an alternative IP address:

10.0.2.2

The Type Provider is NOT happy when I use 10.0.2.2

Replacing "localhost" with "10.0.2.2" on the IP address results in a compilation error stemming from the TypeProvider not establishing a connection to the updated IP address.

The following code will not compile when I attempt to use "10.0.2.2" as the alternative IP (AKA: workaround) which is the required IP for the emulator to work:

[<Literal>]      (* "10.0.2.2" is the workaround IP for local host *)
let JsonPath =   "http://10.0.2.2:48213/api/cars"
type Repository = JsonProvider<JsonPath>

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

let getCars() =

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

In conclusion, how can I access a file via a WebAPI service run locally, and still keep the Type Provider happy when executing the Type Provider on an Emulator?

Sign In or Register to comment.