C#C
C#โ€ข4y ago
Doombox

JsonSerializer.DeserializeAsync() randomly hangs indefinitely [Answered]

private static async Task<T> TryReadDataFromFile<T>(string basePath) where T : class
{
    var filepath = GetFilePath<T>(basePath);
    if (!File.Exists(filepath)) return null;
    await using var filestream = File.Open(filepath, FileMode.Open);
    var res = await JsonSerializer.DeserializeAsync<T>(filestream); // This line
    await filestream.DisposeAsync();
    return res;
}

System.Text.Json's DeserializeAsync seems to (entirely at random) decide to hang indefinitely, throws no exceptions or anything in the process which is odd, it's always the same file in AppData that causes it to hang.
Was this page helpful?