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.

Ambiguous invocation when using Where() in a file that contains both Cosmos.Linq and System.Linq

See original GitHub issue

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

Describe the bug When attempting to use Where() from System.Linq in a class that is also importing Microsoft.Azure.Cosmos.Linq, I get the following error:

Ambiguous invocation: System.Collections.Generic.IEnumerable<T> Where<T>(this System.Collections.Generic.IEnumerable<T>, System.Func<T,bool>) (in class Enumerable) System.Linq.IQueryable<T> Where<T>(this System.Linq.IQueryable<T>, System.Linq.Expressions.Expression<System.Func<T,bool>>) (in class Queryable) match

Example method:

` using System.Collections.Generic; using System.Linq;

////Code

   public async Task<IEnumerable<T>> GetItemsAsync(T type)
    {
        var q = _container.GetItemLinqQueryable<T>();
        var iterator = q.Where(x => x.Key === type.Key).ToFeedIterator().ToAsyncEnumerable();
        //More code
    }
    ///Code
    `

To Reproduce

  • Create a new .NET 5 or 6 web Api solution/project ( tried with both)
  • Install Microsoft.Azure.Cosmos
  • In the Controllers/WeatherForecastControllers.cs file, attempt to perform the method above.

IDE gives error stating the Where is ambiguous

Expected behavior I expect to be able to use both System.Linq and the Cosmos Linq extensions without issue.

Actual behavior

Bug mentioned above is highlighted by the IDE:

image

Environment summary SDK Version: 3.21.0 OS Version (e.g. Windows, Linux, MacOSX)

Windows 10

Additional context It is entirely possible I am shooting myself in the foot, but I don’t see how when a brand new project with nothing extra installed except for Microsoft.Azure.Cosmos behaves this way.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Dmo16commented, Oct 6, 2021

@ealsur I’ve tried this:

        IOrderedQueryable<T> q = _container.GetItemLinqQueryable<T>();
        var iterator = q.Where(x => x.Key == type.Key).ToFeedIterator<T>().ToAsyncEnumerable();

And it works, the ambiguity is removed, thanks for the tip!

0reactions
Dmo16commented, Oct 6, 2021

I think so yes, thanks for asking!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ambiguous invocation caused by picking up two versions ...
I had this problem after ReSharper offered to 'reference System.Core' and 'import System.Linq' in a file where I was using a Linq expression ......
Read more >
Resolving the Call Is Ambiguous Error While Using LINQ
In this article, we will learn when the "call is ambiguous" error happens, why the error happens, and how to work around the...
Read more >
System.Linq is Ambiguous - .NET SDK
I'm using net core 3.1 webapi and implement couchbase (in Net Standard library project) but getting errors all of DbSet.
Read more >
LINQ to NoSQL translation - Azure Cosmos DB
If you want to get the NoSQL query that is translated from LINQ, use the ToString() method on the generated IQueryable object.
Read more >
The call is ambiguous between the following methods or ...
The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.Where<TSource>(System.Collections.Generic.
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