runtime: The binary operator Add is not defined for the types 'System.Nullable`1[System.Byte]' and 'System.Nullable`1[System.Byte]'.
enum MyEnum : byte
{
Value_1 = 1,
Value_2 = 2
}
class Program
{
static void Main(string[] args)
{
dynamic d = MyEnum.Value_1;
var x = d + null;
}
}
fails with following error (works as expected without dynamic)
Unhandled Exception: System.InvalidOperationException: The binary operator Add is not defined for the types 'System.Nullable`1[System.Byte]' and 'System.Nullable`1[System.Byte]'.
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 Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.GenerateBinaryOperator(EXPRCALL pExpr)
at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.GetExpression(EXPR pExpr)
at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.GenerateConvert(EXPRCALL pExpr)
at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.VisitCALL(EXPRCALL pExpr)
at Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Dispatch(EXPR pExpr)
at Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Visit(EXPR pExpr)
at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.GenerateLambda(EXPRCALL pExpr)
at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.VisitCALL(EXPRCALL pExpr)
at Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Dispatch(EXPR pExpr)
at Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Visit(EXPR pExpr)
at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.Rewrite(TypeManager typeManager, EXPR pExpr, IEnumerable`1 listOfParameters)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.CreateExpressionTreeFromResult(IEnumerable`1 parameters, ArgumentObject[] arguments, Scope pScope, EXPR pResult)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore(DynamicMetaObjectBinder payload, IEnumerable`1 parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind(DynamicMetaObjectBinder payload, IEnumerable`1 parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)
at Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(DynamicMetaObjectBinder action, RuntimeBinder binder, IEnumerable`1 args, IEnumerable`1 arginfos, DynamicMetaObject onBindingError)
at Microsoft.CSharp.RuntimeBinder.CSharpBinaryOperationBinder.FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
at System.Dynamic.DynamicMetaObject.BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
at System.Dynamic.BinaryOperationBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)
at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (19 by maintainers)
Commits related to this issue
- Correctly handle dynamic lifted enum arithmetic Microsoft.CSharp special-cases enum binary operations, but not when lifted. In most cases the nett result is an expression that will have the same outc... — committed to JonHanna/corefx by JonHanna 7 years ago
- Correctly handle dynamic lifted enum arithmetic Microsoft.CSharp special-cases enum binary operations, but not when lifted. In most cases the nett result is an expression that will have the same outc... — committed to JonHanna/corefx by JonHanna 7 years ago
- Correctly handle dynamic lifted enum arithmetic Microsoft.CSharp special-cases enum binary operations, but not when lifted. In most cases the nett result is an expression that will have the same outc... — committed to JonHanna/corefx by JonHanna 7 years ago
- Correctly handle dynamic lifted enum arithmetic Microsoft.CSharp special-cases enum binary operations, but not when lifted. In most cases the nett result is an expression that will have the same outc... — committed to JonHanna/corefx by JonHanna 7 years ago
- Correctly handle dynamic lifted enum arithmetic Microsoft.CSharp special-cases enum binary operations, but not when lifted. In most cases the nett result is an expression that will have the same outc... — committed to danmoseley/corefx by JonHanna 7 years ago
Or not. PTAL @ dotnet/corefx#16085