Hello,
My project have suddenly started hanging when I run in the editor.
I have disabled all scripts except the one that fetches the data:
using System;
using System.Net.Http;
using System.Threading.Tasks;
using UnityEngine;
public class DataFetcher : MonoBehaviour
{
private static HttpClient httpClient = new();
private static Uri wineUri = new Uri("https://ipecho.net/plain");//
void Start()
{
Debug.Log("fetcher starting");
try
{
string responseBody = FetchData().Result;
Debug.Log(responseBody);
}
catch (HttpRequestException e)
{
Debug.Log("\nException Caught!");
Debug.Log("Message :" + e.Message);
}
}
static async Task<string> FetchData()
{
return await httpClient.GetStringAsync(wineUri);
}
}
I do not ever see the debug log “fetcher starting”.
When I comment out the call to FetchData or replace responseBody with a string like “test”, everything proceeds and the scene loads as expected.
As soon as I involve the HttpClient, Unity hangs forever. I get no errors and have to force-quit.
Can you spot anything wrong here, or suggest how to proceed with debugging this?
Edit to add:
To make sure it isn’t something funky elsewhere in my project, I created a new 2D core project, added an empty GO and then the script above. Unity still hangs. Using 2023.3.11f1.
Can anyone confirm this behaviour, please?