1

Closed

Bug with visiting null constant expressions

description

Hi - there is a minor bug with the visiting of constant expressions when the value is null - the code is this:
 
    protected override Expression VisitSerializableConstantExpression( SerializableConstantExpression expression ) {
        return Expression.Constant(expression.Value);
    }
 
In the case of null, since there is no way for the Expression factory to know the type it defaults to system.object. The can cause other things to break. I changed the code to specify the CLR type as follows, and it works for the Null case:
 
    protected override Expression VisitSerializableConstantExpression( SerializableConstantExpression expression ) {
        if (expression.Value != null)
        {
            return Expression.Constant(expression.Value);
        }
        else
        {
            return Expression.Constant(expression.Value, (Type)expression.Type.GetClrVersion());
        }
    }
 
Thanks, Mark.
Closed Nov 4, 2008 at 8:56 AM by domcon
Thanks!

comments