Azure / azure-cosmos-table-dotnet

.NET SDK for Azure Cosmos Table API
14 stars 6 forks source link

NullReferenceException when using Table API to Query #50

Closed kellywahl closed 4 years ago

kellywahl commented 4 years ago

When using the code below, I get an "Object reference not set to an instance of an object" on the final line. This happens with Microsoft.Azure.Cosmos.Table version 1.07 and 1.06, however works perfectly fine on 1.05. Is there a breaking change with this new version. Please see code to reproduce and full stack trace below:

        CloudStorageAccount storageAccount =
        CloudStorageAccount.Parse("ConnectionStringRemovedForSecurity");
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        CloudTable table = tableClient.GetTableReference("people");
        table.CreateIfNotExists();

        CustomerEntity customer1 = new CustomerEntity("Smith", "John");
        customer1.Email = "john@example.com";
        customer1.PhoneNumber = "111-555-0000";

        // Create the TableOperation that inserts the customer entity.
        var insertOperation = TableOperation.Insert(customer1);

        //Execute the insert operation.
        table.Execute(insertOperation);

        // Read storage
        TableQuery<CustomerEntity> query =
           new TableQuery<CustomerEntity>()
              .Where(TableQuery.GenerateFilterCondition("PartitionKey",
                  QueryComparisons.Equal, "Smith"));
        var list = table.ExecuteQuery(query).ToList();

Stack Trace [NullReferenceException: Object reference not set to an instance of an object.] Microsoft.Azure.Documents.<>c.<.cctor>b9_0() +169 System.Lazy1.CreateValue() +161 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +27 System.Lazy1.get_Value() +12605132 Microsoft.Azure.Documents.CustomTypeExtensions.ByPassQueryParsing() +129 Microsoft.Azure.Documents.Query.d3.MoveNext() +1253 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64 Microsoft.Azure.Documents.Linq.d36`1.MoveNext() +233 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +26 Microsoft.Azure.Cosmos.Table.Extensions.d2`1.MoveNext() +673 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64 Microsoft.Azure.Cosmos.Table.Extensions.<b__0>d.MoveNext() +907

[StorageException: Object reference not set to an instance of an object.] Microsoft.Azure.Cosmos.Table.Extensions.<b0>d.MoveNext() +951 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64 Microsoft.Azure.Cosmos.Table.Extensions.d21.MoveNext() +893 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64 Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionExecutor.ExecuteQuerySegmented(TableQuery1 query, TableContinuationToken token, CloudTableClient client, CloudTable table, EntityResolver1 resolver, TableRequestOptions requestOptions, OperationContext operationContext) +270 Microsoft.Azure.Cosmos.Table.TableQuery1.ExecuteQuerySegmentedInternal(TableContinuationToken token, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext) +367 Microsoft.Azure.Cosmos.Table.<>cDisplayClass42_0.b0(TableContinuationToken continuationToken) +317 Microsoft.Azure.Cosmos.Table.d21.MoveNext() +66 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +186 System.Linq.Enumerable.ToList(IEnumerable1 source) +61 CosmosTest.Controllers.HomeController.Index() in C:\Users\kelly\Dropbox (KWC)\KWC Private\Dev\Cosmos\CosmosTest\CosmosTest\Controllers\HomeController.cs:36 lambda_method(Closure , ControllerBase , Object[] ) +61 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +157 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27 System.Web.Mvc.Async.<>c.b9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 System.Web.Mvc.Async.<>cDisplayClass11_0.b0() +58 System.Web.Mvc.Async.<>cDisplayClass11_2.b2() +228 System.Web.Mvc.Async.<>cDisplayClass7_0.b1(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>cDisplayClass3_6.b4() +35 System.Web.Mvc.Async.<>cDisplayClass3_1.b1(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.<>c.b152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45 System.Web.Mvc.<>c.b151_2(IAsyncResult asyncResult, Controller controller) +13 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.<>c.b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9836613 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

iant-ee commented 4 years ago

1.0.6 doesn't even have any release notes. https://docs.microsoft.com/en-us/azure/cosmos-db/table-sdk-dotnet-standard

I can't find the source code to see what actually changed.

sakash279 commented 4 years ago

I tried to repro with the steps you mentioned, but could not get a proper repro of the issue. Could you share the version of the document client in the setup as well?

I had v2.1.3 in my setup, which is the default Microsoft.Azure.DocumentDB.Core version with SDK 1.0.6. If you notice the error stack, it is calling into Microsoft.Azure.Documents.Query.. This was apparently a known issue in their nuget package : https://github.com/Azure/azure-cosmos-dotnet-v2/issues/750 https://github.com/Azure/azure-cosmos-dotnet-v2/issues/774

If you try with the versions described in these solutions, do you still see the failure?

We will make the source code available in the near future, just do not have an exact date for now. There is no breaking change between 1.0.5 - 1.0.7 that should be causing this change in behavior.

sakash279 commented 4 years ago

To be more clear, Microsoft.Azure.DocumentDB.Core versions > 2.11.0 should not have this issue. This is supported with the Tables 1.0.7 package.

kellywahl commented 4 years ago

I can confirm that upgrading Microsoft.Azure.DocumentDB.Core to version 2.11.2 (the latest available at the time of posting) has fixed the issue. Thanks for the help.

ghidalgo3 commented 4 years ago

Just for posterity I want to report that I also had this exact issue and that upgrading Microsoft.Azure.DocumentDB.Core to 2.11.5 fixed it. I am using Microsoft.Azure.Cosmos.Table.1.0.7.

What a nightmare!