locked
Found Bug at System.Core.dll RRS feed

  • Question

  • User2092222339 posted

    .Net Framework 4.6

     

    Sample Code

    Expression left = Expression.Constant(value, typeof(DateTime));
    Expression right = Expression.Constant(value2, typeof(DateTime));
     
    //works corretly 
    System.Linq.Expressions.Expression sub = Expression.Subtract(left, right);
     
    //The binary operator Add is not defined for the types 'System.DateTime' and 'System.DateTime'
    System.Linq.Expressions.Expression searchExpression = Expression.Add(left, right);
    

    NOTE:-Left and right both of type System.DateTime

     

     

    Exception Details

     

    An exception of type 'System.InvalidOperationException' occurred in System.Core.dll but was not handled in user code

    Additional information: The binary operator Add is not defined for the types 'System.DateTime' and 'System.DateTime'.

     

    Stack Trace:

       at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)

       at System.Linq.Expressions.Expression.Add(Expression left, Expression right, MethodInfo method)

       at System.Linq.Expressions.Expression.Add(Expression left, Expression right)

       at MyClass.Filter[TEntity,TProperty](IQueryable`1 source, Expression`1 property, TProperty value)

     

    Saturday, February 11, 2017 6:50 AM

Answers

  • User753101303 posted

    Hi,

    It seems actually correct. This is not because you can subtract two datetimes (which give a duration) that you can add two datetimes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 11, 2017 11:06 PM