title: How to Call a Generic Method using "Expression.Parameter" and "Expression.Call" APIs
body: <p>Using the <strong>Expression Tree API</strong> I want to generate code for code that looks like this:</p>
  
  <pre><code>FieldInfo enumFieldInfo = enumFieldInfoSet.SingleOrDefault(fieldInfo =&gt; fieldInfo.Name == enumName);
  </code></pre>
  
  <p>I have written this code but it's not working:</p>
  
  <pre><code>var enumerableType = typeof(Enumerable);
  var enumerableGenericType = typeof(IEnumerable&lt;&gt;).MakeGenericType(typeof(FieldInfo));
  var predicateGenericType =  typeof(Func&lt;&gt;).MakeGenericType(typeof(Func&lt;FieldInfo, bool&gt;));
  
  ParameterExpression fieldInfoSource = Expression.Parameter(enumerableGenericType, "fieldInfoSource");
  ParameterExpression predicateSource = Expression.Parameter(predicateGenericType, "funcPredicateOnFieldInfo");
  
  var arrayOfTypes = new Type[] { enumerableGenericType, predicateGenericType };
  
  MethodCallExpression SingleOrDefaultMethodCall = Expression.Call(enumerableType, "SingleOrDefault",arrayOfTypes, fieldInfoSource, predicateSource);
  </code></pre>
  
  <p>Here is the runtime error: No generic method 'SingleOrDefault' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. </p>
  
  <p>I have tried a number of combinations of type coercion but still have not stumbled on the right combination. I know that the SingleOrDefault is an Extension method on the Enumerable class and that it needs two parameters; I've look at the code via the debugger and have written to code inspect its properties at run-time; what am I missing.</p>