MapsterMapper / MapsterMapper/Mapster

Error: stack overflow when RequireExplicitMapping = true

Open
#571 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug configuration problem
Dominant language
C#
Stars
5.2k
Forks
410
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Hi! This code generates StackOverlowException while calling method Compile() on versions 7.2.0 , 7.3.0 and 7.4-pre:

```
using Mapster;

var config = new TypeAdapterConfig
{
RequireExplicitMapping = true, // comment this to remove StackOverlowException
RequireDestinationMemberSource = true
};
config.NewConfig()/*.MaxDepth(10)*/;
config.Compile(); // StackOverlowException here

public class Source
{
public string? Identifier { get; set; }
public Source[]? Inner { get; set; }
}

public class Destination
{
public string? Identifier { get; set; }
public Destination[]? Inner { get; set; }
}
```

I found two workarounds to avoid this problem:

- remove "RequireExplicitMapping = true" at TypeAdapterConfig initialization
- set MaxDepth for mapping confuguration (see commented example above)

But both solutions are not suitable for me. Is this behavior a bug and how else can it be avoided?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal C# reproduction with Mapster 7.2.0, 7.3.0, or 7.4-pre and inspect the Compile() path used with RequireExplicitMapping and recursive Source[]/Destination[] members. Trace how the mapping configuration handles the recursive types without MaxDepth; done means Compile() no longer raises StackOverflowException while both required-mapping settings remain enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.