riok / mapperly

A .NET source generator for generating object mappings. No runtime reflection.

Home Page:https://mapperly.riok.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Many to many relationship mapping makes the app crash and exit with "Access violation"

sekulicb opened this issue · comments

Describe the bug
Case where one class or record "A" has property of another type "B", and that same type "B" has property of type "A"

Declaration code

public record RoleDto(
    int Id,
    string Name,
    bool IsAdmin,
    IEnumerable<PermissionDto>? Permissions
) : BaseDto(Id);

public record PermissionDto(
    int Id,
    string Name,
    IEnumerable<RoleDto> Roles
) : BaseDto(Id);

What have I tried:

  • [Mapper(UseReferenceHandling = true)]
  • [MapperIgnoreTarget(nameof(PermissionDto.Roles))] on public static partial PermissionDto MapToDto(Permission entity) method

What worked:

  • Removing IEnumerable Roles property

Environment (please complete the following information):

  • Mapperly Version: [3.5.1.]
  • Nullable reference types: [enabled]
  • .NET Version: [e.g. .NET 8.0.100]
  • Target Framework: [.net8.0]
  • Compiler Version: [e.g. 4.8.09037]
  • C# Language Version: [e.g. 12.0]
  • IDE: [Visual Studio v17.8.1]
  • OS: [Windows 10 ]

Additional context
Instead of removing property, I would like to keep it.

commented

Looks like a duplicate of #785. You need to ignore one of these two properties until #785 is supported.