Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Access Violation

Open KC-Cygnia opened this issue 10 months ago • 6 comments

When mapping to an Input application crashes with no info when doing a multilevel mapping on EF Classes [SupplyParameterFromForm] public InputModel Input { get; set; } = new();

public class InputModel : myClass
    {

    }
public class myClass
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime DateTimeStamp { get; set; } = DateTime.Now;
        public List<Thing>? Things{ get; set; }
    }
public class Thing
    {
        public int Id { get; set; }
        public string ThingName { get; set; }
        public DateTime DateTimeStamp { get; set; } = DateTime.Now;
        public List<AnotherThing>? AnotherThings{ get; set; }
        public myClass myClass { get; set; }
        public int myClassId { get; set; }
        
    }
public class AnotherThing    
{
        public int Id { get; set; }
        public string AnotherThingName { get; set; }
        public DateTime DateTimeStamp { get; set; }
        public Thing Thing { get; set; }
        public int ThingId { get; set; }
    }

Crashes on:

Input = _myClass.Adapt<InputModel>();

Crash error: The program '[53536] MyApp.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.

KC-Cygnia avatar Feb 10 '25 11:02 KC-Cygnia

Hello @KC-Cygnia Please indicate the version of Mapster you are using? If possible, check on the latest pre-release version.

DocSvartz avatar Feb 10 '25 12:02 DocSvartz

Hi @DocSvartz I'm using 7.4.0

KC-Cygnia avatar Feb 10 '25 12:02 KC-Cygnia

Hello @KC-Cygnia Please indicate the version of Mapster you are using? If possible, check on the latest pre-release version.

Pre release version 7.4.2-pre02 also crashes

KC-Cygnia avatar Feb 10 '25 12:02 KC-Cygnia

possible linked with #720

DocSvartz avatar Feb 10 '25 13:02 DocSvartz

@KC-Cygnia Based on your class structure (which appears to be recursive) I'm going to go out on a limb and guess that you are encountering circular recursion which leads to a stack overflow, which produces the access violation error. See if any of these options can help you.

andrerav avatar Feb 10 '25 16:02 andrerav

@KC-Cygnia Based on your class structure (which appears to be recursive) I'm going to go out on a limb and guess that you are encountering circular recursion which leads to a stack overflow, which produces the access violation error. See if any of these options can help you.

Hi, Thanks, inline mapping and max depth helped as it was going in a loop of backward navigation, hence the error. May I suggest making maxdepth by default or handling the stack overflow? Hope this thread will help others with this issue. Thank you

KC-Cygnia avatar Feb 11 '25 08:02 KC-Cygnia