Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Type Checks still run after ConvertUsing in 5.0 #1380

Closed
richardlawley opened this issue Jun 28, 2016 · 1 comment
Closed

Additional Type Checks still run after ConvertUsing in 5.0 #1380

richardlawley opened this issue Jun 28, 2016 · 1 comment
Labels
Milestone

Comments

@richardlawley
Copy link

When registering a custom type converter, I would expect no additional checks to be performed when validating the configuration. Instead, an exception is thrown if a type exists that cannot be automatically converted:

public class A
{
    public string Foo { get; set; }
}
public class B
{
    public C Foo { get; set; }
}
public class C { }

[TestMethod]
public void ConvertUsing_IgnoresProperties()
{
    var config = new MapperConfiguration(cfg =>
    {
        cfg.CreateMap<A, B>().ConvertUsing(x => new B { Foo = new C() });
    });
    config.AssertConfigurationIsValid();
}

This generates the following error:

AutoMapper.AutoMapperConfigurationException: The following property on UnitTestProject8.C cannot be mapped:

Add a custom mapping expression, ignore, add a custom resolver, or modify the destination type UnitTestProject8.C.
Context:
Mapping from type System.String to UnitTestProject8.C

Observations:

  • The error only occurs on properties which exist in TSrc and TDest
  • The error only occurs if there is no mapping between the property types
  • No exception is generated if trying to map using this configuration, only on AssertConfigurationIsValid
@jbogard jbogard added the Bug label Jun 28, 2016
@jbogard jbogard added this to the 5.0.1 milestone Jun 28, 2016
@lock
Copy link

lock bot commented May 7, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants