Linq Cosmos DB ArgumentNullException Exception

Yi Gu 0 Reputation points Microsoft Employee
2025-01-29T19:13:20.8733333+00:00
I am using LinQ on the client side to query Cosmos DB. All the other properties work fine except two properties. One is the "id" and the other is the "RowKey".

I manually checked the database, the type of RowKeys are all string, they all have values.  

What may be the issue? Have anyone had experience with this? Thanks.

In logs, I printed out the query string, e.g.,

Filter is x => ((x.RowKey != null) AndAlso (x.RowKey == "some value")).

The exception is as follows, is it because "id" and "RowKey" are reserved attributes?

Exception occurred: 'System.ArgumentNullException: Invalid handle.
   at System.RuntimeMethodHandle.GetSlot(RuntimeMethodHandleInternal method)
   at System.Attribute.InternalGetCustomAttributes(PropertyInfo element, Type type, Boolean inherit)
   at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
   at Microsoft.Azure.Cosmos.Linq.DefaultCosmosLinqSerializer.SerializeMemberName(MemberInfo memberInfo)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitMemberAccess(MemberExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitBinary(BinaryExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitBinary(BinaryExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitWhere(ReadOnlyCollection`1 arguments, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitMethodCall(MethodCallExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.Translate(Expression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitMethodCall(MethodCallExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.Translate(Expression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitMethodCall(MethodCallExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.Translate(Expression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.SqlTranslator.TranslateQuery(Expression inputExpression, CosmosLinqSerializerOptionsInternal linqSerializerOptions, IDictionary`2 parameters)
   at Microsoft.Azure.Cosmos.Linq.CosmosLinqQuery`1.CreateStreamIterator(Boolean isContinuationExcpected, ScalarOperationKind& scalarOperationKind)
   at Microsoft.Azure.Cosmos.Linq.CosmosLinqQuery`1.CreateFeedIterator(Boolean isContinuationExpected, ScalarOperationKind& scalarOperationKind)
   at Microsoft.Azure.Cosmos.Linq.CosmosLinqQuery`1.ToFeedIterator()
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,749 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,278 questions
{count} votes

1 answer

Sort by: Most helpful
  1. NIKHILA NETHIKUNTA 4,510 Reputation points Microsoft Vendor
    2025-01-30T18:00:39.86+00:00

    @Yi Gu
    Thank you for the question and for using Microsoft Q&A platform.

    As per my understanding you are having trouble querying Cosmos DB using LinQ on the client side. From the error message you provided, it appears that the issue may be related to the fact that "id" and "RowKey" are reserved attributes in Cosmos DB.

    Both id and RowKey are special properties in Cosmos DB. The id property is a required property for all items in Cosmos DB, and RowKey is often used in Table API. These properties might be causing issues if they are being treated as reserved keywords.

    To work around this issue, you can try using a different property name instead of "id" and "RowKey".

    If you have already tried this and are still experiencing issues, it may be helpful to provide more information about the specific query you are trying to run and the data you are working with. This will help me better understand the issue and provide more targeted assistance.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.