Zed_Blade
Zed_Blade

Reputation: 1081

Azure CosmosDB SDK ExecuteNextAsync<T> error

This is in a class library that I'm developing, highly based on the ToDo sample project Cosmos DB ToDo App, to perform the "CRUD" operations on CosmosDB. However, everytime I call this method, the app will suddenly stop and not give any errors whatsoever.

Here's the code that I'm using to perform reads. Right now, the uncommented code is a synchronous call that provides no issues reading from the database.

    public static async Task<IEnumerable<T>> GetItemsAsync<T, E>(Expression<Func<T, bool>> predicate) where T : DocDbEntity<E> where E : class
    {
        string documentType = typeof(E).Name;
        IQueryable<T> query = _client.CreateDocumentQuery<T>(
            UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId))
            .Where(predicate)
            .Where(x => x.DocumentType == documentType);

        List<T> results = new List<T>();
        foreach (var res in query)
        {
            results.Add(res);
        }

        //IDocumentQuery<T> query = _client.CreateDocumentQuery<T>(
        //    UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId))
        //    .Where(predicate)
        //    .Where(x => x.DocumentType == documentType)
        //    .AsDocumentQuery();

        //while (query.HasMoreResults)
        //{
        //    results.AddRange(await query.ExecuteNextAsync<T>());
        //}

        return results;
    }

Whenever I try to use query.ExecuteNextAsync<T>() my application will immediately terminate without giving any errors or pointing to what might be causing the issue nor will it "reply" to the request with the retrieved data. This seems to be working without any issues on the sample app.

I'm using the Microsoft.Azure.DocumentDB package from NuGet @ version 1.19.1

What is causing this issue?

Upvotes: 1

Views: 538

Answers (1)

Zed_Blade
Zed_Blade

Reputation: 1081

The actual problem is not related in any way to ExecuteNextAsync but it was rather than the function that was calling this method returned void, thus preventing the parent caller from waiting for a reply. Once I started returning a Task everything started to work as expected.

Upvotes: 1

Related Questions