Chad McCallum
Chad McCallum

Reputation: 21

.NET Maui on Android Emulator not running httpclient.getasync

Visual Studio 2022, installed the .NET Maui toolkit. File -> New Project with .NET Maui Blazor Hybrid App template.

Open up Home.razor and change to the following:

@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.

<button @onclick="FetchData">Fetch</button>

<div>@data</div>

@code
{
    private string data = "";

    private void FetchData()
    {
        var client = new HttpClient();
        var response = client.GetAsync("https://httpbin.org/get").Result;
        data = response.Content.ReadAsStringAsync().Result;
    }
}

Put a breakpoint on the client.GetAsync call

Run the app with the android emulator (Pixel 5, API 34).

Click the 'Fetch' button, breakpoint hits in visual studio.

Click "Step Over" in the debug toolbar.

Nothing happens. No error message, no next line, nothing.

I attached with the chrome devtools debugger, and no network call is ever made.

I also tried with an async Task FetchData method, no difference.

What am I doing wrong here?

---

Edit: I have tried

None of these changes did anything - they all behave the same way.

Upvotes: 0

Views: 33

Answers (1)

Chad McCallum
Chad McCallum

Reputation: 21

After doing even more searching, I tried getting the emulator to reboot (not just saving state and shutting down), and lo and behold that worked. After the emulator restarted, it was able to make API calls over https.

Leaving this here in cause anyone else runs into the same issue.

Upvotes: 2

Related Questions