Static field requires null instance, non-static field requires non-null instance. Parameter name: expression : <p>I have seen possible solutions to this error, but I just don't understand how to fix mine.
My code looks like this:</p>

<pre><code>}

/// &lt;summary&gt;
/// Gets our data reader
/// &lt;/summary&gt;
/// &lt;param name="reader"&gt;The reader to return&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
private Func&lt;IDataReader, T&gt; GetReader(IDataReader reader)
{
    Delegate resDelegate;

    // For each field, add to our columns
    List&lt;string&gt; readerColumns = new List&lt;string&gt;();
    for (int index = 0; index &lt; reader.FieldCount; index++)
        readerColumns.Add(reader.GetName(index));

    // Determine the information about the reader
    var readerParam = Expression.Parameter(typeof(IDataReader), "reader");
    var readerGetValue = typeof(IDataReader).GetMethod("GetValue");

    // Create a Constant expression of DBNull.Value to compare values to in reader
    var dbNullValue = typeof(DBNull).GetField("Value");
    var dbNullExp = Expression.Field(Expression.Parameter(typeof(DBNull), "System.DBNull"), dbNullValue);

    // Loop through the properties and create MemberBinding expressions for each property
    List&lt;MemberBinding&gt; memberBindings = new List&lt;MemberBinding&gt;();
    foreach (var prop in typeof(T).GetProperties())
    {
        // Determine the default value of the property
        object defaultValue = null;
        if (prop.PropertyType.IsValueType)
            defaultValue = Activator.CreateInstance(prop.PropertyType);
        else if (prop.PropertyType.Name.ToLower().Equals("string"))
            defaultValue = string.Empty;

        // If the column exists
        if (readerColumns.Contains(prop.Name))
        {

            // Build the Call expression to retrieve the data value from the reader
            var indexExpression = Expression.Constant(reader.GetOrdinal(prop.Name));
            var getValueExp = Expression.Call(readerParam, readerGetValue, new Expression[] { indexExpression });

            // Create the conditional expression to make sure the reader value != DBNull.Value
            var testExp = Expression.NotEqual(dbNullExp, getValueExp);
            var ifTrue = Expression.Convert(getValueExp, prop.PropertyType);
            var ifFalse = Expression.Convert(Expression.Constant(defaultValue), prop.PropertyType);

            // Create the actual Bind expression to bind the value from the reader to the property value
            var mi = typeof(T).GetMember(prop.Name)[0];
            var mb = Expression.Bind(mi, Expression.Condition(testExp, ifTrue, ifFalse));
            memberBindings.Add(mb);
        }
    }

    // Create a MemberInit expression for the item with the member bindings
    var newItem = Expression.New(typeof(T));
    var memberInit = Expression.MemberInit(newItem, memberBindings);

    // Create the lambda expression
    var lambda = Expression.Lambda&lt;Func&lt;IDataReader, T&gt;&gt;(memberInit, new ParameterExpression[] { readerParam });
    resDelegate = lambda.Compile();

    // Return our delegate
    return (Func&lt;IDataReader, T&gt;)resDelegate;
}
</code></pre>

<p>and as the title says, the error I get is:</p>

<blockquote>
  <p>Static field requires null instance, non-static field requires non-null instance. Parameter name: expression</p>
</blockquote>

<p>which is this line:</p>

<pre><code>var dbNullExp = Expression.Field(Expression.Parameter(typeof(DBNull), "System.DBNull"), dbNullValue);
</code></pre>

<p>Can anyone tell me why I am getting the error and how to fix it?</p>
