0

I am trying to call this GetNotificationsCount() function from both .Net 6 Forms application and a console application.

public async Task<long> GetNotificationsCount()
{
    var query = @"Match (p:Notification) RETURN count(p) as notificationCount";
    var count = await _dataAccess.ExecuteReadScalarAsync<long>(query);
    return count;
}

this is basically calling a function below:

public async Task<T> ExecuteReadScalarAsync<T>(string query, IDictionary<string, object>? parameters = null)
{
    try
    {
        parameters = parameters == null ? new Dictionary<string, object>() : parameters;
        using (var session = _driver.AsyncSession(o => o.WithDatabase(_database)))
        {
           var result = await session.ExecuteReadAsync(async tx => // <-- ***Fails Here***
            {
                T scalar = default(T);
                var res = await tx.RunAsync(query, parameters);
                scalar = (await res.SingleAsync())[0].As<T>();
                return scalar;
            });
            return result;
        }
    }
    catch (Exception ex)
    {
        // **** Did not reach here either *****
        _logger.LogError(ex, "There was a problem while executing database query");
        throw;
    }
}

Strange Issue I am having is that this exact same code works when I call it behind a button_click() event on a form, however when I call from the console main() function application crashes without any indication or exception.

I am using Neo4j.Driver version 5.3.0 if it makes any difference

does anyone have a clue why this may be happening?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Kiran
  • 2,997
  • 6
  • 31
  • 62

0 Answers0