Ambiguous invocation when using Where() in a file that contains both Cosmos.Linq and System.Linq
See original GitHub issueWe 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:
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:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
@ealsur I’ve tried this:
And it works, the ambiguity is removed, thanks for the tip!
I think so yes, thanks for asking!