Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambigiuous method call between extension methods

Tags:

c#

.net

I have been download DynamicLinq library via nuget package. I used it like below

db.ReservationSet.Where("blbalbabla",1,2)

But i get below exception.

Error 38 The call is ambiguous between the following methods or properties: 'System.Linq.Dynamic.DynamicQueryable.Where(System.Linq.IQueryable, string, params object[])' and 'System.Linq.Dynamic.DynamicQueryable.Where(System.Linq.IQueryable, string, params object[])' F:\Projects\IEKeysNew\IEKEYS\Controllers\ReportController.cs 145 22 IEKEYS

Here is sign of both methods.

public static IQueryable<T> Where<T>(this IQueryable<T> source, string predicate, params object[] values);
public static IQueryable Where(this IQueryable source, string predicate, params object[] values);

I could not find something to get rid of this compile time exception.

like image 884
Freshblood Avatar asked Jul 24 '12 11:07

Freshblood


People also ask

How can use generic extension method in C#?

Extension Methods is a new feature in C# 3.0 and the Common Language Runtime, which allows existing classes to use extra methods (extension methods) without being implemented in the same class or obtained by inheritance.

What is the difference between a static method and an extension method?

The only difference between a regular static method and an extension method is that the first parameter of the extension method specifies the type that it is going to operator on, preceded by the this keyword.

Can extension methods access private methods?

Extension methods cannot access private variables in the type they are extending.

How do you call an extension method?

To define and call the extension methodDefine a static class to contain the extension method. The class must be visible to client code. For more information about accessibility rules, see Access Modifiers. Implement the extension method as a static method with at least the same visibility as the containing class.


1 Answers

Unfortunately another third party .dll library contains the same dynamic linq library internaly. Trirand's jQGrid library contains dynamic linq library and that is the reason for the conflict when I import System.Linq.Dynamic library.

like image 98
Freshblood Avatar answered Nov 01 '22 01:11

Freshblood