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

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:

The Type Provider is NOT happy when I use

Replacing "localhost" with "" 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 "" as the alternative IP (AKA: workaround) which is the required IP for the emulator to work:

[<Literal>]      (* "" is the workaround IP for local host *)
let JsonPath =   ""
type Repository = JsonProvider<JsonPath>

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

let getCars() =

    Repository.Load JsonPath
    |> Array.toSeq
    |> 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.