title: MemberExpression: InvalidOperationExpression variable 'x' referenced from scope '', but it is not defined
body: <p>I'm using <a href="http://msdn.microsoft.com/en-us/library/bb506649.aspx">System.Linq.Expressions</a></p>
  
  <p>I was attempting to build a simple <a href="http://msdn.microsoft.com/en-us/library/bb342202.aspx">LambdaExpression</a> that includes a <a href="http://msdn.microsoft.com/en-us/library/system.linq.expressions.memberexpression.aspx">MemberExpression</a>. If I create the MemberExpression explicitly with the System.Linq.Expressions API (e.g. <a href="http://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.makememberaccess.aspx">MakeMemberAccess</a>), I will get the error "InvalidOperationExpression variable 'x' referenced from scope '', but it is not defined" when I call Compile() on the LambdaExpression.</p>
  
  <p>For example ,this is my code</p>
  
  <pre><code>Expression&lt;Func&lt;Customer, string&gt;&gt; expression1, expression2, expression3;
  Func&lt;Customer, string&gt; fn;
  expression1 = (x) =&gt; x.Title;
  fn = expression1.Compile();//works
  fn(c);
  MemberExpression m;
  m = Expression.MakeMemberAccess(
  Expression.Parameter(typeof(Customer), "x"), typeof(Customer).GetProperty("Title"));
  expression2 = Expression.Lambda&lt;Func&lt;Customer, string&gt;&gt;(m,
      Expression.Parameter(typeof(Customer), "x"));
  
  m = Expression.Property(Expression.Parameter(typeof(Customer),"x"), "Title");
  expression3 = Expression.Lambda&lt;Func&lt;Customer, string&gt;&gt;(m,
      Expression.Parameter(typeof(Customer), "x"));
  
  fn = expression3.Compile();//InvalidOperationExpression variable 'x' referenced from scope '', but it is not defined
  fn = expression2.Compile();//InvalidOperationExpression variable 'x' referenced from scope '', but it is not defined
  </code></pre>
  
  <p>expression2 and expression3 throw an exception when the Compile() method is called, but expression1 does not; expression1 works. Why is this?  How do I create an MemberExpression like in expressions 2, 3 and get them to work (not throw an exception) when I call Compile()?</p>
  
  <p>Thanks</p>