This function works find in a console app:
private async Task TestAsync()
{
var client = new RestClient("https://weatherbit-v1-mashape.p.rapidapi.com/current?lang=en&lon=%3Crequired%3E&lat=%3Crequired%3E");
var request = new RestRequest(Method.GET);
request.AddHeader("x-rapidapi-host", "weatherbit-v1-mashape.p.rapidapi.com");
request.AddHeader("x-rapidapi-key", "d6c6-omitted");
IRestResponse response = await client.ExecuteAsync(request).ConfigureAwait(false);
return;
}
But when run inside a xamarin app, this code never finished execution. The task is called, but never finishes. Same thing with every other request I've tried.
Specifications
Xamarin: 4.6.0.1141+555-sha.ec64e9186-azdo.3888486
RestSharp: 106.11.7
Edit:
Here is more code:
class Program
{
static void Main(string[] args)
{
var x = TestAsync().Result;
int y = 0;
}
private static async Task<IRestResponse> TestAsync()
{
var client = new RestClient("https://weatherbit-v1-mashape.p.rapidapi.com/current?lang=en&lon=%3Crequired%3E&lat=%3Crequired%3E");
var request = new RestRequest(Method.GET);
request.AddHeader("x-rapidapi-host", "weatherbit-v1-mashape.p.rapidapi.com");
request.AddHeader("x-rapidapi-key", "d6c61a25cfmshfc1caea2f83287fp1e287cjsn695b47d979fb");
IRestResponse response = await client.ExecuteAsync(request);
return response;
}
}
this works fine, however the following doesn't work:
public partial class App : Application
{
public App()
{
InitializeComponent();
var x = TestAsync().Result;
int y = 0;
DependencyService.Register<MockDataStore>();
MainPage = new AppShell();
}
private static async Task<IRestResponse> TestAsync()
{
var client = new RestClient("https://weatherbit-v1-mashape.p.rapidapi.com/current?lang=en&lon=%3Crequired%3E&lat=%3Crequired%3E");
var request = new RestRequest(Method.GET);
request.AddHeader("x-rapidapi-host", "weatherbit-v1-mashape.p.rapidapi.com");
request.AddHeader("x-rapidapi-key", "d6c61a25cfmshfc1caea2f83287fp1e287cjsn695b47d979fb");
IRestResponse response = await client.ExecuteAsync(request);
return response;
}
protected override void OnStart()
{
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}