Execute a cypher query using .NET Driver

What is the correct way of executing a Cypher query from .NET?

After reading multiple forums and blog posts, I came to the following approach as "the" correct way.

var driver = GraphDatabase.Driver(getUri(), AuthTokens.Basic("username", "password"));

using var session = driver.AsyncSession(x => x.WithDefaultAccessMode(AccessMode.Write));

var queryResult = await session.ExecuteWriteAsync(async x =>
{
    IResultCursor cursor = await x.RunAsync(GetQuery());
    return await cursor.ToListAsync();
});

This approach works; however, if an error occurs executing the query, the program "halts" with no exceptions thrown.

I tried the following, but even in this case, no exception is caught if an error occurs executing the query.

var queryResult = await session.ExecuteWriteAsync(async x =>
{
    try
    {
        IResultCursor cursor = await x.RunAsync(GetQuery());
        return await cursor.ToListAsync();
    }
    catch(Exception e)
    { }
});

This is a hard-to-reproduce issue, as in some cases, I get the exception (e.g., if there was an issue with the syntax of the query), but sometimes the program simply halts (waits indefinitely) at executing this. Since there is no error message, I am unsure what causes the issue. If I repeat executing a query with this approach, it runs successfully in most cases but halts in a handful of runs with no error. Since the query does not change between the runs, I suppose the issue be related to the driver.