Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AutoMapper/ConstructorMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public Expression NewExpression(Expression instanceParameter)
var matchingExpressionConverter =
ExpressionResultConverters.FirstOrDefault(c => c.CanGetExpressionResolutionResult(result, map));

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last two nulls are not needed.


return result;
});
Expand Down
36 changes: 36 additions & 0 deletions src/UnitTests/Projection/MoreExplanatoryExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using AutoMapper.QueryableExtensions;

namespace AutoMapper.UnitTests.Projection
{
public class MoreExplanatoryExceptionTests
{
[Fact]
public void ConstructorWithUnknownParameterTypeThrowsExplicitException()
{
// Arrange
var config = new MapperConfiguration(cfg =>
cfg.CreateMap<EntitySource, EntityDestination>());

// Act
var exception = Assert.Throws<AutoMapperMappingException>(() =>
new EntitySource[0].AsQueryable().ProjectTo<EntityDestination>(config));

// Assert
Assert.Contains("object notSupported", exception.Message, StringComparison.OrdinalIgnoreCase);
}

class EntitySource
{
}
class EntityDestination
{
public EntityDestination(object notSupported = null) { }
}
}
}