I have an issue with the following code, working well in a Console App project and not working in a ASP.NET Web Forms project, both targeting .NET Framework 4.7.2.
The goal is to use the last Azure Cosmos DB SDK (v3) to get all documents in a container, without specifying a type (use of dynamic).
I've tried to target both the emulator (the last version 2.4.5) and the Azure Cosmos service.
In the ASP.NET project, the execution of queryResultSetIterator.ReadNextAsync().Result never ends (no timeout).
string endpointUri = "https://localhost:8081";
string primaryKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
string database = "SendGridEvents";
string collection = "SendGridEvents";
using (CosmosClient client = new CosmosClient(endpointUri, primaryKey))
{
Container container = client.GetDatabase(database).GetContainer(collection);
QueryDefinition queryDefinition = new QueryDefinition("SELECT * FROM c");
FeedIterator<dynamic> queryResultSetIterator = container.GetItemQueryIterator<dynamic>(queryDefinition);
List<dynamic> documents = new List<dynamic>();
while (queryResultSetIterator.HasMoreResults)
{
FeedResponse<dynamic> currentResultSet = queryResultSetIterator.ReadNextAsync().Result;
foreach (var document in currentResultSet)
{
documents.Add(document);
}
}
}