title: variable 'x' of type 'Product' referenced from scope, but it is not defined
body: <p>I have a class named <code>Product</code> in class library project. I am using <code>SubSonic SimpleRepository</code> to persist objects. I have a method as follows in <code>Product</code> class:</p>
  
  <pre><code>public static IList&lt;Product&gt; Load(Expression&lt;Func&lt;Product, bool&gt;&gt; expression)
  {
      var rep=RepoHelper.GetRepo("ConStr");
      var products = rep.Find(expression);
      return products.ToList();
  }
  </code></pre>
  
  <p>I'm calling this function like this:</p>
  
  <pre><code>private void BindData()
  {
      var list = Product.Load(x =&gt; x.Active);//Active is of type bool
      rptrItems.DataSource = list;
      rptrItems.DataBind();
  }
  </code></pre>
  
  <p>Calling <code>Load</code> from <code>BindData</code> throws the exception:</p>
  
  <pre><code>variable 'x' of type 'Product' referenced from scope '', but it is not defined
  </code></pre>
  
  <p>How can I resolve this.</p>
  
  <p>EDIT:- by stepping through <code>SubSonic</code> code I found that the error is thrown by this function</p>
  
  <pre><code>private static Expression Evaluate(Expression e)
  {
      if(e.NodeType == ExpressionType.Constant)
          return e;
      Type type = e.Type;
      if(type.IsValueType)
          e = Expression.Convert(e, typeof(object));
      Expression&lt;Func&lt;object&gt;&gt; lambda = Expression.Lambda&lt;Func&lt;object&gt;&gt;(e);
      Func&lt;object&gt; fn = lambda.Compile(); //THIS THROWS EXCEPTION
      return Expression.Constant(fn(), type);
  }
  </code></pre>