-
Notifications
You must be signed in to change notification settings - Fork 71
NullReferenceException: Object reference not set to an instance of an object. #7
Description
I just tried "Quick-start" sample for .net Core and integrated in .NET Core 2.0 App and I am getting error as:
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
Test.DocumentDBRepository+d__6.MoveNext() in DocumentDBRepository.cs, line 43
Note: The same code is working perfectly in .NET Core V1 with run-time 1.0.4
NullReferenceException: Object reference not set to an instance of an object.
Test.DocumentDBRepository+d__6.MoveNext() in DocumentDBRepository.cs
+
IDocumentQuery query = client.CreateDocumentQuery(
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Test.Controllers.ItemController+d__0.MoveNext() in ItemController.cs
+
var items = await DocumentDBRepository.GetItemsAsync(d => !d.Completed);
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__12.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__10.MoveNext()
Code:
public static async Task<IEnumerable<T>> GetItemsAsync(Expression<Func<T, bool>> predicate)
{
IDocumentQuery<T> query = client.CreateDocumentQuery<T>(
UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId),
new FeedOptions { MaxItemCount = -1 })
.Where(predicate)
.AsDocumentQuery();
List<T> results = new List<T>();
while (query.HasMoreResults)
{
results.AddRange(await query.ExecuteNextAsync<T>());
}
return results;
}