agileobjects / ReadableExpressions

A library and Debugger Visualizer which translates Expression Trees into readable C# source code. .NET 3.5+ and .NET Standard 1.0+.
MIT License
396 stars 22 forks source link

Ut-oh An exception occurred translating that Expression`1 #147

Open ziggy90127 opened 1 month ago

ziggy90127 commented 1 month ago

I have about 240 maps, I get this error on 3 of them. Not sure if this is enough for you to get a handle on the problem. Here's 1 map from my .net 4.6.1 app. ReadableExpressions v4.7.1

this.CreateMap<ImportEntityViewModel, ImportEntity>() .ForMember(dest => dest.JsonData, opt => opt.Ignore()) .ForMember(dest => dest.ScoreData, opt => opt.Ignore()) .ForMember(dest => dest.Score, opt => opt.Ignore()) .ForMember(dest => dest.IsConflicted, opt => opt.Ignore()) .ForMember(dest => dest.IsManual, opt => opt.Ignore()) .ForMember(dest => dest.ImportId, opt => opt.Ignore()) .ForMember(dest => dest.ImportEntityId, opt => opt.Ignore()) .ForMember(dest => dest.Name, opt => opt.Ignore());

Ut-oh An exception occurred translating that Expression1.

Please report this error with the stack trace below using https://github.com/agileobjects/ReadableExpressions/issues/new .

Thanks! (and sorry about that) Steve


System.NullReferenceException: Object reference not set to an instance of an object. at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.GetEnumValue(Expression expression, Type enumValueType) at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.TryGetEnumComparisonExpression(BinaryExpression comparison, Expression& leftOperand, Expression& rightOperand) at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.For(BinaryExpression binary, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.ConditionTranslation.For(Expression condition, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.TernaryTranslation..ctor(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.For(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.AssignmentTranslation.GetNonDefaultValueTranslation(Expression assignedValue, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.AssignmentTranslation..ctor(ExpressionType nodeType, INodeTranslation targetTranslation, Expression value, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.AssignmentTranslation..ctor(BinaryExpression assignment, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.TryCatchTranslation.GetBlockTranslation(Expression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.TryCatchTranslation..ctor(TryExpression tryCatchFinally, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.TernaryTranslation..ctor(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.For(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.LambdaTranslation..ctor(LambdaExpression lambda, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslation() at AgileObjects.ReadableExpressions.Visualizers.ObjectSource.ExpressionVisualizerObjectSource.GetData(Object target, Stream outgoingData, Action2 serializer)

SteveWilkes commented 1 month ago

Hi! Thanks for letting me know - could you give me the definitions of ImportEntityViewModel and ImportEntity and any other classes they depend on? Thanks!

ziggy90127 commented 1 month ago

With Automapper version 11 and higher, the bug doesn't show in this .net 8 console app, but happens for lower versions. Unfortunately the maximum Automapper version that works in .net framework is 9.0.0, my app is .net 4.8.1.

` using System; using AutoMapper; using System.Diagnostics; // For Debugger.Break()

namespace AutoMapperDemo { // Define the ImportOperation2 enum without any members public enum ImportOperation2 { }

// Source class with ImportOperation2 member
public class Source
{
    public ImportOperation2? Operation { get; set; }
}

// Destination class with ImportOperation2 member
public class Destination
{
    public ImportOperation2? Operation { get; set; }
}

// AutoMapper Profile
public class MappingProfile : Profile
{
    public MappingProfile()
    {
        // Define the mapping configuration for ImportOperation2
        CreateMap<Source, Destination>();
    }
}

class Program
{
    static void Main(string[] args)
    {
        // Configure AutoMapper
        var config = new MapperConfiguration(cfg =>
        {
            cfg.AddProfile<MappingProfile>();
        });

        // Create the Mapper instance
        var mapper = config.CreateMapper();

        // Build the execution plan
        var executionPlan = config.BuildExecutionPlan(typeof(Source), typeof(Destination));

        // Trigger a break in the debugger before writing to console
        Debugger.Break();

        // Display the execution plan
        Console.WriteLine("Execution Plan:");
        Console.WriteLine(executionPlan);

        // Wait for a key press before closing the console
        Console.WriteLine("\nPress any key to exit...");
        Console.ReadKey();
    }
}

} `

Ut-oh An exception occurred translating that Expression31.

Please report this error with the stack trace below using https://github.com/agileobjects/ReadableExpressions/issues/new .

Thanks! (and sorry about that) Steve


System.NullReferenceException: Object reference not set to an instance of an object. at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.GetEnumValue(Expression expression, Type enumValueType) at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.TryGetEnumComparisonExpression(BinaryExpression comparison, Expression& leftOperand, Expression& rightOperand) at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.For(BinaryExpression binary, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.ConditionTranslation.For(Expression condition, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.ConditionalTranslationBase..ctor(ConditionalExpression conditional, INodeTranslation ifTrueTranslation, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.ConditionalTranslationBase..ctor(ConditionalExpression conditional, INodeTranslation ifTrueTranslation, INodeTranslation ifFalseTranslation, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.TernaryTranslation..ctor(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.For(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Extensions.PublicTranslationContextExtensions.GetCodeBlockTranslationFor(ITranslationContext context, Expression expression) at AgileObjects.ReadableExpressions.Translations.AssignmentTranslation.GetNonDefaultValueTranslation(Expression assignedValue, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.AssignmentTranslation.GetValueTranslation(Expression assignedValue, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.AssignmentTranslation..ctor(ExpressionType nodeType, INodeTranslation targetTranslation, Expression value, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.AssignmentTranslation..ctor(BinaryExpression assignment, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockAssignmentStatementTranslation..ctor(BinaryExpression assignment, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Extensions.PublicTranslationContextExtensions.GetCodeBlockTranslationFor(ITranslationContext context, Expression expression) at AgileObjects.ReadableExpressions.Translations.TryCatchTranslation.GetBlockTranslation(Expression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.TryCatchTranslation.GetReturnableBlockTranslation(Expression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.TryCatchTranslation..ctor(TryExpression tryCatchFinally, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Extensions.PublicTranslationContextExtensions.GetCodeBlockTranslationFor(ITranslationContext context, Expression expression) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.TernaryTranslation..ctor(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ConditionalTranslation.For(ConditionalExpression conditional, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.BlockStatementTranslation..ctor(Expression expression, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.BlockTranslation.GetBlockStatements(BlockExpression block, ITranslationContext context, Boolean& hasMultiStatementStatement, Boolean& hasGoto, Boolean& isEmpty) at AgileObjects.ReadableExpressions.Translations.BlockTranslation..ctor(BlockExpression block, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Extensions.PublicTranslationContextExtensions.GetCodeBlockTranslationFor(ITranslationContext context, Expression expression) at AgileObjects.ReadableExpressions.Translations.LambdaTranslation..ctor(LambdaExpression lambda, ITranslationContext context) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression) at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslation() at AgileObjects.ReadableExpressions.ExpressionExtensions.ToReadableString(Expression expression, Func2 configuration) at AgileObjects.ReadableExpressions.Visualizers.ObjectSource.ExpressionVisualizerObjectSource.GetTranslationFor(Object target) at AgileObjects.ReadableExpressions.Visualizers.ObjectSource.ExpressionVisualizerObjectSource.GetData(Object target, Stream outgoingData, Action2 serializer)`

SteveWilkes commented 1 month ago

Thanks for the detail - I'll look into it!