AutoMapper / AutoMapper.Collection

AutoMapper support for updating existing collections by equivalency
MIT License
245 stars 59 forks source link

Elaborate on "You cannot include a type map into itself" error #112

Closed Deilan closed 2 years ago

Deilan commented 6 years ago

Please elaborate on "You cannot include a type map into itself" InvalidOperationException exception message. As of AutoMapper 7.0.1 it's the only info provided in the exception, which doesn't help to troubleshoot a problem.

TylerCarlson1 commented 6 years ago

Sorry for not getting to this earlier. Where in AutoMapper.Collections is this error occurring and what is the exact exception? Can you make a gist to replicate the problem so I can see what you're talking about.

Also AutoMapper isn't a cloning library so mapping an object to itself isn't an officially supported use case.

B45man commented 3 years ago

Bump. I just ran into this error, and nowhere in the stacktrace does it say what types caused this. My code is a loop that goes through a bunch of types in different namespaces but with identical properties. For each pair of types I call this code:

            profile.CreateMap<T, T2>()
                     .IncludeBase<T, T2>();

Obviously it's my own code that's the problem, but I would like it if Automapper tells me what types T and T2 are. "You cannot include a type map into itself" is not a useful error message in my opinion.

lbargaoanu commented 3 years ago

@B45man A PR is welcome.

PeshekhonovK commented 2 years ago

Hi Everyone, I see that this specific issue is covered in current master, but still we encountered another related issue - if for some reason, any profile is added twice, we get this "cannot include a type map into itself" error, that is totally not convenient for debugging. What do you think about adding profile uniqueness check to MapperConfigurationExpression.AddProfile method or to MapperConfiguration constructor? This way we could get contextual error with list of profiles affected and probably in first case we could also fulfill fail-fast approach.

Tasteful commented 2 years ago

What are the exact exception with call-stack for this issue, can you make a gist to replicate the problem so we can see what you're talking about? I think the issue is more related to AM than AM.Collection, can that be the case?

PeshekhonovK commented 2 years ago

What are the exact exception with call-stack for this issue, can you make a gist to replicate the problem so we can see what you're talking about? I think the issue is more related to AM than AM.Collection, can that be the case?

Yes, you are right, I found this issue by error, so probably just wrong repo. Sorry, will ask in correct one