StackOverflowException

64 views
Skip to first unread message

F D

unread,
Jan 11, 2021, 4:45:39 AM1/11/21
to AutoMapper-users
Hello, 

 I am working on an application which includes a service which interfaces with a database. When I save certain classes, the return mapping causes a StackOverflowException Here is the context The dto classes are generated automatically by ado.Net entity. I get circular references.  

AutoMapper version : 6.2.2

Sample: 

    public partial class dim_site
    { ...
        public virtual ICollection<dim_site_caracteristiques> dim_site_caracteristiques { get; set; }
}
public partial class dim_site_caracteristiques
    {  ...
        public virtual dim_site dim_site { get; set; }
        public virtual ICollection<lien_caracteristique_tarif> lien_caracteristique_tarif { get; set; }
    }
    public partial class lien_caracteristique_tarif
    { ...
        public virtual dim_site_caracteristiques dim_site_caracteristiques { get; set; }

}


With these classes, AutoMapper throws a StackOverflowException

Sample:

// I save a dim_site in the database.
// The mapper works in this direction

Communication.Contract.Mangrove.dim_site result = SaveSite(Context, AutoMapper.Mapper.Map<Communication.Contract.Mangrove.dim_site>(site)
// We map the result in the other direction. There the StackOverflowException exception occurs
            return AutoMapper.Mapper.Map<Business.Service.Dto.Canopee.dim_site>(result);


F D

unread,
Jan 15, 2021, 3:10:31 AM1/15/21
to AutoMapper-users

I don't think I'm the first or the last to have this problem. I have a project stuck while waiting for a solution. For now, I'm stuck. Has this problem been fixed in a newer version of Automapper?  

Jimmy Bogard

unread,
Jan 15, 2021, 8:48:42 AM1/15/21
to automapper-users
No idea, sorry, I don't use circular references. The easiest solution is to set MaxDepth so you say for the circular reference "only go N many cycles in depth".
--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/automapper-users/f6894de6-95da-4f0a-a9be-ebd3e8ff82f0n%40googlegroups.com.

F D

unread,
Jan 15, 2021, 9:38:30 AM1/15/21
to AutoMapper-users
Thank you for this solution. I do not know. I'm going to try
Reply all
Reply to author
Forward
0 new messages