-
Notifications
You must be signed in to change notification settings - Fork 74
Description
Version
I'm using the latest version of AutoMapper.Collection: 11
AutoMapper is on version 14.0.0 (but also happened on 13.0.1, the latest possible on .NET Core 6)
Problem
I have a parent object which has a lot of properties.
If I then try to map the parent, then the application crashes.
Since it is a StackoverflowException, it won't be caught and it isn't handy to find the origin of the crash.
I managed to track it down to one specific property; an object with a list of childobjects, but the childobject again had a list with references to the parentobject (and in theory others of the same type: but in this case it only has the parent).
Strangely it doesn't give an issue without the AutoMapper.Collection; then aparently the list is flattened and somehow it returns the reference to the parent while PreserveReferences isn't added to the parent type nor the child.
Workarounds
If I add PreserveReferences()
, to all classes then it works. (also possible with cfg.Internal().ForAllMaps((map, opts) => opts.PreserveReferences());
)
If I would delete cfg.AddCollectionMappers();
, then the error also disapears.
Wish
It would be handy if it doesn't result in a StackoverflowException.
A normal exception would make it possible to view the stacktrace and possible have a meaningfull message/type.
Other mentions
I see that there was another tickets mentioning the StackoverflowException. However is is about older versions and is closed:
#188