Problem with expressions variable 'buffer' of type 'System.Text.StringBuilder' referenced from scope '', but it is not defined
<p><pre>
private Func GenerateWriter()
{
    MethodInfo appendMethod = typeof(StringBuilder).GetMethod("Append", 
        new[] { typeof(string) });</p>

<code>var buffer = Expression.Variable(typeof(StringBuilder), "buffer");
var writer = new List&lt;Expression&gt;();
var source = Expression.Parameter(typeof(string[]));
writer.Add(Expression.Assign(buffer, Expression.New(typeof(StringBuilder))));

//add some strings to buffer

writer.Add(Expression.Call(buffer, "ToString", null));
var f = Expression.Lambda&lt;Func&lt;string[], string&gt;&gt;
    (Expression.Block(writer.ToArray()), source).Compile();
return f;
</code></pre>

<p>}

I have gotten such message: 
<strong>variable 'buffer' of type 'System.Text.StringBuilder'
referenced from scope '', but it is not defined</strong></p>

<p>I do not understand what the error. Everything seems correct.
Help me, please!</p>
