question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException when using GetItemLinqQueryable without partition key in LINQ filters

See original GitHub issue

Describe the bug When I try to get items from the database using the GetItemLinqQueryable method without partition key in LINQ filters, I get NullReferenceException at await cosmosQuery.CountAsync();. As soon as I add the partition key to LINQ filters, everything works.

To Reproduce Sample code here.

Expected behavior Using GetItemLinqQueryable without LINQ filter for partition key does not throw an exception. The queryable returns the items matching the filters.

Actual behavior Using GetItemLinqQueryable without LINQ filter for partition key throws an exception.

Exception details:

System.Reflection.TargetInvocationException:` Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
 at lambda_method(Closure )
 --- End of inner exception stack trace ---
 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
 at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
 at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.EvaluateConstant(Expression expression)
 at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.Visit(Expression expression)
 at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visit
or)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.Visit(Expression expression)
   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.Visit(Expression expression)
   at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
   at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.Visit(Expression expression)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
 
  at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.Visit(Expression expression)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.Visit(Expression expression)
   at Microsoft.Azure.Cosmos.Linq.SubtreeEvaluator.Evaluate(Expression expression)
   at Microsoft.Azure.Cosmos.Linq.ConstantEvaluator.PartialEval(Expression expression, Func`2 fnCanBeEvaluated)
   at Microsoft.Azure.Cosmos.Linq.ConstantEvaluator.PartialEval(Expression expression)
   at Microsoft.Azure.Cosmos.Li
nq.SqlTranslator.TranslateQuery(Expression inputExpression, CosmosLinqSerializerOptions linqSerializerOptions, IDictionary`2 parameters)
   at Microsoft.Azure.Cosmos.Linq.DocumentQueryEvaluator.HandleMethodCallExpression(MethodCallExpression expression, IDictionary`2 parameters, CosmosLinqSerializerOptions linqSerializerOptions)
   at Microsoft.Azure.Cosmos.Linq.DocumentQueryEvaluator.Evaluate(Expression expression, CosmosLinqSerializerOptions linqSerializerOptions, IDictionary`2 parameters)
   at Microsoft.Azure.Cosmos.Linq.CosmosLinqQuery`1.CreateFeedIterator(Boolean isContinuationExpected)
   at Microsoft.Azure.Cosmos.Linq.CosmosLinqQuery`1.AggregateResultAsync(CancellationToken cancellationToken)
   at CosmosTest.Service.CosmosDbClient.GetLeadsAsync(LeadsSearch search) in C:\\Project\\CosmosTest\\Service\\CosmosDbClient.cs:line 33

Environment summary SDK Version: 3.18.0 OS Version (e.g. Windows, Linux, MacOSX): Edition Windows 10 Pro Version 20H2 OS build 19042.985 Experience Windows Feature Experience Pack 120.2212.2020.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
azzimuthcommented, May 19, 2021

@j82w, done

0reactions
azzimuthcommented, May 21, 2021

@j82w, yes, we will consider changing the partition key to the other field.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem using LINQ queries with GetItemLinqQueryable ...
But if I move the linq query as part of the GetItemLinqQueryable, I get an error "IQueryable does not contain a definition for...
Read more >
Is ParitionKey required for GetItemLinqQueryable call? ...
Please describe. I would like some documentation clarifying whether or not a partition key is required when using GetItemLinqQueryable in order ...
Read more >
Problem using LINQ queries with GetItemLinqQueryable for ...
[Solved]-Problem using LINQ queries with GetItemLinqQueryable for CosmosDB-LINQ,C# ... maxconcurrency = -1, partitionkey = partitionkey.none;// may be null ...
Read more >
LINQ to NoSQL translation - Azure Cosmos DB
Where: Filters translate to WHERE, and support translation between && , || , and ! to the NoSQL operators; SelectMany: Allows unwinding of ......
Read more >
Container.GetItemLinqQueryable<T> Method
This method creates a LINQ query for items under a container in an Azure Cosmos DB service. IQueryable extension method ToFeedIterator() should be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found