title: 'Argument expression is not valid' when creating anonymous types dynamically
body: <p>I'm creating an expression tree builder to return custom anonymous types. I tried it first with discrete types and it works ok, but using TypeBuilder to build types at runtime and pass that type to the expression tree fail with this error</p>
  
  <pre><code>'Argument expression is not valid'
  </code></pre>
  
  <p>here is the code I use:</p>
  
  <p>this method I use to create the anonymous type</p>
  
  <pre><code>private Type CreateAnonymousType(Dictionary&lt;string, Type&gt; properties)
      {
        AssemblyName dynamicAssemblyName = new AssemblyName("MyAssembly");
        AssemblyBuilder dynamicAssembly = AssemblyBuilder.DefineDynamicAssembly(dynamicAssemblyName, AssemblyBuilderAccess.Run);
        ModuleBuilder dynamicModule = dynamicAssembly.DefineDynamicModule("MyAssembly");
  
        TypeBuilder dynamicAnonymousType = dynamicModule.DefineType("ReturnType", TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass);
        foreach (var p in properties)
        {
          dynamicAnonymousType.DefineField(p.Key, p.Value, FieldAttributes.Public);
        }
  
        return dynamicAnonymousType.CreateType();
      }
  </code></pre>
  
  <p>and here is how I create the expression tree</p>
  
  <pre><code>var cars = new List&lt;Car&gt;();
        for (int i = 0; i &lt; 10; i++)
        {
          cars.Add(new Car { Id = i, Name = "Car " + i, Age = 2010 + i });
        }
  
  
        IQueryable&lt;Car&gt; allCars = cars.AsQueryable();
  
        var properties = new Dictionary&lt;string, Type&gt;
        {
          { "Id", typeof(int) },
          { "Name", typeof(string) }
        };
  
        ParameterExpression x = Expression.Parameter(typeof(Car), "x");
        var listMembers = properties.Select(p =&gt; Expression.Property(x, p.Key));
  
        var returnType = CreateAnonymousType(properties);
        object destObject = Activator.CreateInstance(returnType);
  
  
        var listBind = listMembers.Select(p =&gt; Expression.Bind(returnType.GetField(p.Member.Name), p));
  
        var result = Expression.New(returnType);
        var initExp = Expression.MemberInit(result, listBind.ToArray());
  
  
        var call = Expression.Call(typeof(Queryable), "Select",
            new Type[] {
              typeof(Car),
              returnType
          }
          , Expression.Constant(allCars)
          , Expression.Lambda(initExp, x));
  
        var qResult = allCars.Provider.CreateQuery&lt;IdName&gt;(call);
  
        foreach (var car in qResult)
        {
          Console.WriteLine(car.Id + " - " + car.Name);
        }
  </code></pre>
  
  <p>the error happened while CreateQuery method executes</p>