MapsterMapper / MapsterMapper/Mapster

Compile doesn't throw exceptions while configuring with attributes

Open
#666 0 comments 0 reactions 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

While im configuring with attributes
```
[AdaptFrom(typeof(Foo))]
public record Bar(string Title);
public record Foo(string Name);
```
These records are supposed to throw an error during **Compile()**, but it doesn't happen
```
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource= true;
TypeAdapterConfig.GlobalSettings.Compile(); // successfull?? why??
var foo= new Foo("Name");
var bar= foo.Adapt(); // Exception: corresponding source member mapped or ignored:Title
```

On the other hand, if I configure using an interface:
`IMapFrom`
or utilize the method:
`TypeAdapterConfig.GlobalSettings.ForType();`

In this scenario, everything works fine
```
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource= true;
TypeAdapterConfig.GlobalSettings.Compile(); // Exception: corresponding source member mapped or ignored:Title
```
Why is this happening?
(lib: Mapster v7.4.0)

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 with the [AdaptFrom] configuration and compare it with IMapFrom and ForType() during Compile(). Reproduce the records example with RequireDestinationMemberSource enabled, then trace when the missing Title member is validated. Done means Compile() reports the same missing-member error for attribute configuration as it does for the other two paths.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.