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

4.2.0 .Include<DerivedSourceType, DerivedTargetType> throws exception with base type names #1077

Closed
PehrGit opened this issue Feb 3, 2016 · 8 comments

Comments

@PehrGit
Copy link

PehrGit commented Feb 3, 2016

Creating a map and including a map which doesn't exist throws an exception that doesn't really help find the missing map.

Consider the following:

`

    public class SourceDerived
    {
    }

    public interface IMyInterface
    {
    }

    public class TargetDerived : IMyInterface
    {
    }

    [TestMethod]
    public void MyTestMethod()
    {
        var config = new MapperConfiguration(cfg =>
            cfg.CreateMap<object, IMyInterface>()
                .Include<SourceDerived, TargetDerived>()
            );
    }

`
The test throws an exception with message :

System.InvalidOperationException: Missing map from Object to IMyInterface. Create using Mapper.CreateMap<Object, IMyInterface>.

It is right to throw because I have not defined a map from SourceDerived to TargetDerived.

In my opinion it would be much more helpful if the message read:

System.InvalidOperationException: Missing map from SourceDerived to TargetDerived. Create using Mapper.CreateMap<SourceDerived , TargetDerived>.

@jbogard If you agree, I would happily provide a PR

@PehrGit PehrGit changed the title .Include<DerivedSourceType, DerivcedTargetType> throws exception with base type names 4.2.0 .Include<DerivedSourceType, DerivedTargetType> throws exception with base type names Feb 3, 2016
@jbogard
Copy link
Member

jbogard commented Feb 3, 2016

Anything that you "Include" has to include its own CreateMap call. Them's the rules.

@lbargaoanu
Copy link
Member

@jbogard @PehrGit means this.

@jbogard
Copy link
Member

jbogard commented Feb 3, 2016

@lbargaoanu
Copy link
Member

:)

@PehrGit
Copy link
Author

PehrGit commented Feb 3, 2016

@lbargaoanu @jbogard That's sort of what I mean, but my point is actually that that test asserts that the message contains the name of the base type, not the derived type.

This:

ex=>ex.Message.ShouldStartWith("Missing map from Object to BaseType."));

Should be, in my humble opinion:

ex=>ex.Message.ShouldStartWith("Missing map from Object to ChildType."));

@lbargaoanu
Copy link
Member

Yes, the original test was wrong.

@PehrGit
Copy link
Author

PehrGit commented Feb 3, 2016

Yay I helped!

@lbargaoanu lbargaoanu mentioned this issue Feb 3, 2016
@jbogard jbogard closed this as completed in 4f343b2 Feb 8, 2016
@jbogard jbogard added this to the 5.0.0 milestone Feb 8, 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.
Projects
None yet
Development

No branches or pull requests

3 participants