Skip to content

Exception thrown when mapping .ToTarget() using context #68

@SlowLogicBoy

Description

@SlowLogicBoy

Code that reproduces the problem:

var mapper = Mapper.CreateNew();
mapper.WhenMapping
    .From<FromModel>()
    .To<ToModel>()
    .Map((s, t) => s.Statistics) //Works Fine
    //.Map(ctx => ctx.Source.Statistics) //Exception thrown
    .ToTarget();

I changed my code to use .Map((s, t) => s.Statistics) instead of .Map(ctx => ctx.Source.Statistics) Just letting you know that this exist ;)

Exception:

System.InvalidOperationException: variable 'vToYvData' of type 'AgileObjects.AgileMapper.ObjectPopulation.IObjectMappingData`2[FromModel,ToModel]' referenced from scope '', but it is not defined
   at void System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
   at Expression System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node)
   at Expression System.Linq.Expressions.ParameterExpression.Accept(ExpressionVisitor visitor)
   at Expression System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at Expression System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at Expression System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at Expression System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at Expression System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at Expression System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at Expression System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at Expression[] System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at Expression System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Expression System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at Expression System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at ReadOnlyCollection<Expression> System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection<Expression> nodes)
   at Expression System.Linq.Expressions.Compiler.VariableBinder.VisitLambda<T>(Expression<T> node)
   at Expression System.Linq.Expressions.Expression<TDelegate>.Accept(ExpressionVisitor visitor)
   at Expression System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
   at Delegate System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)
   at TDelegate System.Linq.Expressions.Expression<TDelegate>.Compile(bool preferInterpretation)
   at TValue AgileObjects.AgileMapper.Caching.ArrayCache<TKey, TValue>.GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
   at Type AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingData<TSource, TTarget>.GetSourceMemberRuntimeType(IQualifiedMember childSourceMember)
   at IObjectMappingData AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingData<TSource, TTarget>.WithSource(IQualifiedMember newSourceMember)
   at MappingCreationContext AgileObjects.AgileMapper.ObjectPopulation.MappingExpressionFactoryBase+MappingCreationContext.WithDataSource(IDataSource newDataSource)
   at IEnumerable<Expression> AgileObjects.AgileMapper.ObjectPopulation.MappingExpressionFactoryBase.GetConfiguredRootDataSourcePopulations(MappingCreationContext context)+MoveNext()
   at void System.Collections.Generic.List<T>.AddEnumerable(IEnumerable<T> enumerable)
   at void System.Collections.Generic.List<T>.InsertRange(int index, IEnumerable<T> collection)
   at Expression AgileObjects.AgileMapper.ObjectPopulation.MappingExpressionFactoryBase.Create(IObjectMappingData mappingData)
   at ObjectMapper<TSource, TTarget> AgileObjects.AgileMapper.ObjectPopulation.ObjectMapperFactory.Create<TSource, TTarget>(ObjectMappingData<TSource, TTarget> mappingData)
   at IObjectMapper AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingData<TSource, TTarget>.GetOrCreateMapper()
   at TValue AgileObjects.AgileMapper.Caching.ArrayCache<TKey, TValue>.GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
   at ObjectMapper<TSource, TTarget> AgileObjects.AgileMapper.ObjectPopulation.ObjectMapperFactory.GetOrCreateRoot<TSource, TTarget>(ObjectMappingData<TSource, TTarget> mappingData)
   at new AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingData<TSource, TTarget>(TSource source, TTarget target, Nullable<int> enumerableIndex, MappingTypes mappingTypes, IMappingContext mappingContext, IObjectMappingData declaredTypeMappingData, IObjectMappingData parent, bool createMapper)
   at ObjectMappingData<TSource, TTarget> AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingDataFactory.ForRootFixedTypes<TSource, TTarget>(TSource source, TTarget target, MappingTypes mappingTypes, IMappingContext mappingContext)
   at ObjectMappingData<TSource, TTarget> AgileObjects.AgileMapper.ObjectPopulation.ObjectMappingDataFactory.ForRootFixedTypes<TSource, TTarget>(TSource source, TTarget target, IMappingContext mappingContext)
   at TTarget AgileObjects.AgileMapper.MappingExecutor<TSource>.PerformMapping<TTarget>(TTarget target)
   at TResult AgileObjects.AgileMapper.MappingExecutor<TSource>.ToANew<TResult>()

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions