I am using Dynamic LINQ in an ASP.NET MVC project to create queries at runtime.
First I create a string from client's request like this:
string predicate = GetPredicateString(request);
The predicate
would have a value like "AvailableFrom = DateTime(2015, 10, 05)"
Then in my code I call ParseLambda
method of DynamicLinq.DynamicExpression
class like below.
var lambda = DynamicExpression.ParseLambda(typeof(Product), typeof(bool), predicate)
Doing so I receive the following exception:
Unable to cast object of type 'System.Reflection.RuntimeConstructorInfo' to type 'System.Reflection.MethodInfo'.
Line 1958: int FindBestMethod(IEnumerable<MethodBase> methods, Expression[] args, out MethodBase method){
Line 1959: MethodData[] applicable =
methods
.Select(m => new MethodData
{
MethodBase = m,
Parameters = m.GetParameters()
.Where(p => p.ParameterType != (MethodInfo)m).ReturnType).ToArray()
})
.Where(m => IsApplicable(m,args)).ToArray();
this part of the above fragment must be throwing the exception:
(MethodInfo)m)
I have tried to pass arguments matching other constructor overloads of DateTime
structure, but it doesn't make any difference. So one can rule out passing invalid arguments being the cause.
I have to say that I am getting this exception only with DateTime
and all other data types (string
, int
etc.) cause no problem.
I haven't found anything similar in the Internet, so I guess either I am doing something wrong or this is a very rare situation.
Any idea on how to resolve this issue would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire