Skip to content

No support for Linq expressions using ReadOnlySpan methods #5518

@MindaugasButkus

Description

@MindaugasButkus

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

Describe the bug
After upgrading to .NET 10 noticed that some filters started throwing NotSupportedException. After investigation I narrowed it down to change in the Contains method - it's now an extension method on the ReadOnlySpan struct, which does not implement IEnumerable interface. As it does not implement IEnumerable interface, the BuiltinFunctionVisitor no longer interprets it as an array.

To Reproduce

using Microsoft.Azure.Cosmos; // 3.56.0

var client = new CosmosClient("AccountEndpoint=https://test.url;AccountKey=test");

var container = client.GetContainer("a", "a");

var enumerable = new[] { "a" }.AsEnumerable();
var linq1 = container.GetItemLinqQueryable<string>()
    .Where(x => enumerable.Contains(x));

Console.WriteLine(linq1.ToString()); // Prints {"query":"SELECT VALUE root FROM root WHERE (root IN (\"a\"))"}

var array = new[] { "a" };
var linq2 = container.GetItemLinqQueryable<string>()
    .Where(x => array.Contains(x));

Console.WriteLine(linq2.ToString()); // Throws NotSupportedException

Expected behavior
Should work the same way as with Enumerables.

Actual behavior
Throws NotSupportedException.

Environment summary
SDK Version: 3.56.0
OS Version (e.g. Windows, Linux, MacOSX) - irrelevant.

Additional context
Noticed during migration from .NET 8 to .NET 10. ReadOnlySpan received some optimizations and methods were rewritten to work with it. Therefore, the Contains method was affected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions