mapperly icon indicating copy to clipboard operation
mapperly copied to clipboard

fix: prevents incorrect RMG020 warning

Open Andrei-hub11 opened this issue 6 months ago • 4 comments

Fix: prevents incorrect RMG020 warning

Description

Fixes issue where RMG020 "The member .. on the mapping source type ... is not mapped to any member on the mapping target type ." warnings were incorrectly reported when user mappings with MapperIgnoreSource attributes were used in collection element mapping scenarios.

For more details, see issue #1793.

Solution: Modified EnumerableMappingBuilder to detect when user mappings exist for non-nullable element types and use FindOrBuildLooseNullableMapping instead of FindOrBuildMapping. This preserves user mapping configurations (like MapperIgnoreSource attributes) and prevents false positive diagnostics.

Fixes #1793

Checklist

  • [x] The existing code style is followed
  • [x] The commit message follows our guidelines
  • [x] Performed a self-review of my code
  • [x] Hard-to-understand areas of my code are commented
  • [ ] The documentation is updated (as applicable)
  • [x] Unit tests are added/updated
  • [ ] Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

Andrei-hub11 avatar Jun 02 '25 00:06 Andrei-hub11

@latonz I tried applying the suggestion in #1793 (comment) — specifically ignoring IUserMapping in MappingBuilderContext.BuildDelegatedMapping. Unless I misunderstood something, the suggested fix didn’t resolve the issue. Please let me know if you'd like me to explore a different approach, make any changes, or if the current solution looks good to you.

Andrei-hub11 avatar Jun 03 '25 21:06 Andrei-hub11

Thank you for your contribution! Why didn't the idea (ignoring IUserMapping in MappingBuilderContext.BuildDelegatedMapping) work?

latonz avatar Jun 12 '25 11:06 latonz

@latonz I'm not sure, but I tried something like this:

var existingMapping = FindMapping(source, target);

if (existingMapping is IUserMapping)
{
    return null;
}

The early return happens when I'm debugging the test that reproduces the error, but the warning still appears.

Andrei-hub11 avatar Jun 12 '25 16:06 Andrei-hub11

The easiest way to identify the source of a diagnostic is to set a breakpoint in DiagnosticCollection.ReportDiagnostic. To narrow it down, you can add a condition to the breakpoint that matches the specific RMG number you want to trace.

latonz avatar Jun 13 '25 08:06 latonz