hazzik / DelegateDecompiler

A library which is able to decompile a delegate or a method body to its lambda representation
MIT License
526 stars 62 forks source link

No coercion operator is defined between types 'System.Int32' and 'System.Nullable`1[System.Boolean]'. - regression between 0.29.1 and 0.30.0 #183

Closed NetMastr5 closed 1 year ago

NetMastr5 commented 2 years ago

Upgraded from 0.29.1 to 0.30.0 and now receive this error

No coercion operator is defined between types 'System.Int32' and 'System.Nullable`1[System.Boolean]'.

[InvalidOperationException: No coercion operator is defined between types 'System.Int32' and 'System.Nullable1[System.Boolean]'.] System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType) +3659028 DelegateDecompiler.Processor.Process() +38324 DelegateDecompiler.Processor.Process(VariableInfo[] locals, IList1 args, Instruction instruction, Type returnType) +350 DelegateDecompiler.MethodBodyDecompiler.DecompileConcrete(MethodInfo method, IList1 args) +285 DelegateDecompiler.MethodBodyDecompiler.Decompile(MethodInfo method, Type declaringType) +328 System.Lazy1.CreateValue() +243 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +32 System.Lazy1.get_Value() +14194428 DelegateDecompiler.DecompileExpressionVisitor.Decompile(MethodInfo method, Expression instance, IList1 arguments) +61 System.Linq.Expressions.ExpressionVisitor.VisitConditional(ConditionalExpression node) +83 System.Linq.Expressions.ExpressionVisitor.VisitMemberAssignment(MemberAssignment node) +22 System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes, Func2 elementVisitor) +86 System.Linq.Expressions.ExpressionVisitor.VisitMemberInit(MemberInitExpression node) +142 System.Linq.Expressions.ExpressionVisitor.VisitLambda(Expression`1 node) +30 System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node) +22 System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) +89 System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) +57 DelegateDecompiler.DecompiledQueryProvider.CreateQuery(Expression expression) +60

This error occurs when materializing a query from an entity to a view model, where the entity has a nullable bool field that is computed from an underlying string field and assigned to a nullable bool field on the view model


~~~ Entity Fields ~~~
[Column("YNTSD")]
[MaxLength(400)]
private string _yesNoPdcoe { get; set; }

[NotMapped]
[Computed]
public bool? yesNoPdcoe
{
    get => this._yesNoPdcoe == "Yes" ? true : (this._yesNoPdcoe == "No" ? (bool?)false : null);
    set => this._yesNoPdcoe = value.HasValue && value.Value ? "Yes" : (value.HasValue ? "No" : null);
}

~~~ Model Fields ~~~
public bool? yesNoPdcoe { get; set; }

~~~Here is the linq query~~~

MachineOrder order = this.machineOrderRepository.GetById2(idToLoad.Value)
    .Select(x => new MachineOrder {
        yesNoPdcoe = x.yesNoPdcoe
    })
    .Decompile()
    .FirstOrDefault();
hazzik commented 1 year ago

This has been released in 0.31.0. Please consider ❤️ supporting the project.