title: Lambda compilation throws "variable '' of type '' referenced from scope '', but it is not defined"
body: <p>When I attempt to compile the lambda shown below, it throws:</p>
  
  <p>variable 'model' of type 'System.Collections.Generic.IEnumerable`1[WheelEndCatalogKendo.Models.SapBasicData]' referenced from scope '', but it is not defined</p>
  
  <pre><code>public static GridBoundColumnBuilder&lt;TModel&gt; BuildColumnString&lt;TModel&gt;(this GridBoundColumnBuilder&lt;TModel&gt; column, WebViewPage&lt;IEnumerable&lt;TModel&gt;&gt; webViewPage, int width) where TModel : class {
      var modelParameter = Expression.Parameter(typeof(IEnumerable&lt;TModel&gt;), "model");
      Expression&lt;Func&lt;IEnumerable&lt;TModel&gt;, TModel&gt;&gt; firstItem = (model) =&gt; model.FirstOrDefault();
      var member = MemberExpression.Property(firstItem.Body, column.Column.Member);
      var lambda = Expression.Lambda&lt;Func&lt;IEnumerable&lt;TModel&gt;, string&gt;&gt;(member, modelParameter);
      var title = webViewPage.Html.DisplayNameFor(lambda).ToHtmlString();
      var header = webViewPage.Html.ShortLabelFor(lambda).ToHtmlString().FixUpNewLinesAsHtml();
      var compiled = lambda.Compile(); //Throws here with "variable '...' of type '...' referenced from scope '', but it is not defined"
  ....
  }
  </code></pre>
  
  <p>I see several similar posts; but so far they haven't clued me in to the problem with my code.  It seems like I am supplying the lambda variable (as the 2nd parameter argument).  I have however almost no experience authoring expression trees.</p>
  
  <p>Any ideas?</p>