Uh oh!
There was an error while loading. Please reload this page.
Better error message when the creation of the instantiation expression fails - #2421
Conversation
| public Expression NewExpression(Expression instanceParameter) | ||
| { | ||
| var parameters = CtorParams.Select(map => | ||
| try |
There was a problem hiding this comment.
I don't think we need the extra try/catch. Some exceptions are really bugs and need no user friendly messages.
| namespace AutoMapper.QueryableExtensions | ||
| { | ||
| public class BuilderException : Exception |
There was a problem hiding this comment.
I don't think we need a new exception type here. AutoMapperMappingException should do. Just pass it the types so it's easy to understand what's going on.
There was a problem hiding this comment.
Uses now AutoMapperMappingException
| { | ||
| cfg.CreateMap<EntitySource, EntityDestination>(); | ||
| }); | ||
| var exception = Assert.Throws<BuilderException>(() => config.ExpressionBuilder.GetMapExpression<EntitySource, EntityDestination>()); |
There was a problem hiding this comment.
ProjectTo is the API, so the test should call that. GetMapExpression is just an internal thing.
There was a problem hiding this comment.
ProjectTo is now used by unit test.
| result = matchingExpressionConverter?.GetExpressionResolutionResult(result, map) | ||
| ?? throw new Exception("Can't resolve this to Queryable Expression"); | ||
| result = matchingExpressionConverter?.GetExpressionResolutionResult(result, map) | ||
| ?? throw new AutoMapperMappingException($"Unable to generate the instantiation expression for the constructor {Ctor}: no expression could be mapped for constructor parameter '{map.Parameter}'.", null, TypeMap.Types, null, null); |
There was a problem hiding this comment.
The last two nulls are not needed.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
While defining a new mapping between two classes, I was getting a mysterious
Can't resolve this to Queryable Expressionerror message. The message was not meaningful enough so I had to debug AutoMapper to understand what the problem was. I simply had to tell AutoMapper which constructor had to be used...This PR intends to generate a more explanatory error message.