You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An ArgumentException when AutoMapper tries to access a property to the wrong object.
As you can see by the exception below SubQueryPath.GetSourceExpression is trying to access the property Bar on the object Bar, which does not exist. Strangely, it only happens when projecting Foos, not when projecting Bars
System.ArgumentException
HResult=0x80070057
Message=Property 'MapRepro.Entities.Bar Bar' is not defined for type 'MapRepro.Entities.Bar' (Parameter 'property')
Source=System.Linq.Expressions
StackTrace:
at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)
at System.Linq.Expressions.Expression.MakeMemberAccess(Expression expression, MemberInfo member)
at System.Linq.Expressions.MemberExpression.Update(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
at AutoMapper.QueryableExtensions.Impl.ProjectionBuilder.FirstPassLetPropertyMaps.SubQueryPath.GetSourceExpression(Expression parameter)
at AutoMapper.QueryableExtensions.Impl.ProjectionBuilder.FirstPassLetPropertyMaps.<>c__DisplayClass11_0.<GetSubQueryExpression>b__0(SubQueryPath path)
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at AutoMapper.QueryableExtensions.Impl.ProjectionBuilder.FirstPassLetPropertyMaps.GetSubQueryExpression(ProjectionBuilder builder, Expression projection, TypeMap typeMap, ProjectionRequest& request, ParameterExpression instanceParameter)
at AutoMapper.QueryableExtensions.Impl.ProjectionBuilder.CreateProjection(ProjectionRequest& request, LetPropertyMaps letPropertyMaps)
at AutoMapper.Internal.LockingConcurrentDictionary`2.<>c__DisplayClass2_1.<.ctor>b__1()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at AutoMapper.QueryableExtensions.Impl.ProjectionBuilder.GetProjection(Type sourceType, Type destinationType, Object parameters, MemberPath[] membersToExpand)
at AutoMapper.QueryableExtensions.Extensions.ToCore(IQueryable source, Type destinationType, IConfigurationProvider configuration, Object parameters, IEnumerable`1 memberPathsToExpand)
at AutoMapper.QueryableExtensions.Extensions.ToCore[TResult](IQueryable source, IConfigurationProvider configuration, Object parameters, IEnumerable`1 memberPathsToExpand)
at MapRepro.Program.Main(String[] args) in C:\Users\alexander.DIVINELOGIC\source\repos\MapRepro\MapRepro\Program.cs:line 24
varcontext=newClientContext(newDbContextOptionsBuilder<ClientContext>().UseInMemoryDatabase("Test").Options);// Bar -> Baz -> Widgets.FirstOrDefault() // OKAYvarresultOkay=mapper.ProjectTo<Models.BarModel>(context.Bars);// Foo -> Bar -> Baz -> Widgets.FirstOrDefault()// System.ArgumentException: 'Property 'MapRepro.Entities.Bar Bar' is not defined for type 'MapRepro.Entities.Bar' (Parameter 'property')'varresultNotOkay=mapper.ProjectTo<Models.FooModel>(context.Foos);
This discussion was converted from issue #4256 on March 21, 2023 19:20.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Source/destination types
Mapping configuration
Version: 12.0.1
EF Core 7.0.3
EF Core InMemory 7.0.3
Expected behavior
A valid mapping and successful projection
Actual behavior
An
ArgumentExceptionwhen AutoMapper tries to access a property to the wrong object.As you can see by the exception below
SubQueryPath.GetSourceExpressionis trying to access the propertyBaron the objectBar, which does not exist. Strangely, it only happens when projecting Foos, not when projecting BarsSteps to reproduce
See gist: https://gist.github.com/MrZander/0bcdd5a9b8b42e862b5b523b0d49002a
All reactions