The type arguments for method cannot be inferred from the usage
Get<S, T>
takes two type arguments. When you call service.Get(new Signatur());
how does the compiler know what T
is? You'll have to pass it explicitly or change something else about your type hierarchies. Passing it explicitly would look like:
service.Get<Signatur, bool>(new Signatur());
The type arguments for method … cannot be inferred from the usage. Try specifying the type arguments explicitly
Because you have defined the parameter of type object
while the method MapIntToString
has first parameter of type int
. So the compiler is not able to figure out that the parameter passed to mapFunc
for Map2
i.e object value
is currently holding value of type int
. Your code will be translated to something like below if we visualize it when will be resolved at run-time but at first place it is not compiling as it's not able to resolve the generic type From
:
Map2<Object, String>(object value, Func<object, String> mapFunc) => mapFunc((object)value);
So, obviously this wouldn't work as your method expects parameter of type int
not object
.
You need to be explicit about the type parameters in this case as Compiler is not smart enough to know that the object value
is currently holding value of type int
in it.
The type arguments for method T cannot be inferred from the usage. Try specifying the type arguments explicitly
You can try specifying the type arguments explicitly. Like this:
var result = LinqFunctions.GroupBy<ProductsList.Product, int, string, KeyValuePair<int, IEnumerable<string>>>(...
UPD.
Also it seems the call should be like this one:
var result = LinqFunctions.GroupBy(products,
keySelector,
elementSelector,
resultSelector,
comparer
);
so the source of error - providing wrong Func
for resultSelector
The type arguments for methods cannot be inferred from the usage. Try specifying the type arguments explicitly
So you want to convert your DataTable to a list of objects of a certain type. Right?
The generic method infers the generic type T
from the parameters only. Since you have no parameters of type T
then you need to explicitly specify it. So when you write this line:
List<string> listNames = CustomerName.ConvertDataTableToList(dt);
The Compiler can't infer what that the type T
you want is a string
because it is only used in the return type. So you need to explicitly specify that:
CustomerName.ConvertDataTableToList<string>(dt);
However, since you specify the condition where T : new()
, this means the generic type should have a parameterless constructor, string doesn't satisfy that. You're matching the row by name, so your only option is to modify the generic methods or create a class like this:
public class CustomerNameHolder
{
public string Name { set; get; }
}
Then:
List<string> listNames = CustomerName.ConvertDataTableToList<CustomerNameHolder>(dt)
.Select(x=> x.Name).ToList();
The type arguments for method cannot be inferred from the usage. Try specifying the type arguments specifically
You don't need TObject
generic parameter in your BuildDictionary
definition, because you already have T
parameter on your class definition with the same meaning (that is - T
is type of object in your repository). So change BuildDictionary
like this:
public Dictionary<TKey, TValue> BuildDictionary<TKey, TValue>(
Expression<Func<T, TKey>> keyExp,
Expression<Func<T, TValue>> valueExp)
You can also remove TObject
from GetValue
, though this is not required:
private TType GetValue<TType>(Expression<Func<T, TType>> exp, T item)
Your current approach does not work because you have two different generic type parameters with the same meaning: T
on class level and TObject
on method level. Your _repo.GetAll()
returns list of T
, but method works with objects of type TObject
which might be different.
The type arguments for method '' cannot be inferred from the usage. Try specifying the type arguments explicitly
In the Constructor<T>()
method you expect a List<T>
type but you provide an instance of IEnumerable<T>
.
- change the method parameter type to
IEnumerable<T>
- convert to query to
List<T>
type
IEnumerable<Colors> c =
db
.Products
.Where(t => t.ProductID == p.ProductID)
.SelectMany(s => s.Colors)
.ToList();
if (c.Any()) sp.color = Constructor(c);
private string Constructor<T>(IEnumerable<T> list)
{
//Do something
}
Lamda Link type arguments cannot be inferred from usage
How can I join an int column to an nullable int?
You need to make them the same type, otherwise the compiler won't be able to decide what TKey is supposed to be because there isn't an implicit conversion between AnonType<int, int>
and AnonType<int?, int?>
e.g. cast the non-nullable ints to be (int?)
so they match
Join(_Context.Clients.Where(c => c.Key == Key),
a => new { AddressId = (int?)a.AddressId, ServerId = (int?)a.ServerId},
c => new { c.AddressId, c.ServerId},
You got away with it before because there was an implicit conversion from int
to int?
for the single key argument, but it would have similarly errored if you'd used anonymous types with a single prop in your join keys:
//this would fail too
Join(_Context.Clients.Where(c => c.Key == Key),
a => new { AddressId },
c => new { c.AddressId },
Related Topics
Xdocument.Validate Is Always Successful
How to Get Information About Recently Connected Usb Device
Ms Dynamics Crm Online 2011 - Authentication Issues
Equivalence of "With...End With" in C#
How to Use Default Serialization in a Custom System.Text.JSON JSONconverter
How to Crop a Polygonal Area from an Image in a Winform Picturebox
Using Prepared Statement in C# with MySQL
C#: How to Get an Object by the Name Stored in String
Can't Change Gameobject Color via Script
Possible Unintended Reference Comparison
Converting String Expression to Integer Value Using C#
The Object Cannot Be Deleted Because It Was Not Found in the Objectstatemanager
Cast Linq Result to Observablecollection
Best Way to Find All Factors of a Given Number