Access localhost from Android virtual machine

Whilst playing with Xamarin I encountered an issue when debugging the Android version of the app. Apparently localhost is not translated causing an error when trying to access an API running on my development machine. Strangely I did not encounter this issue when debugging the IOS version of my app.

To access your localhost (aka your development machine) you need to refer to the IP-address

To work around this issue you can use the DeviceInfo class from Xamarin.Essentials. Just add a statement which checks the type of device the code is being ran on.

string baseAddress =
DeviceInfo.Platform == DevicePlatform.Android ? "" : "http://localhost:25026/file";