question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IncludeBase failure in 4.2 (worked in 4.1 and below)

See original GitHub issue

Since I upgraded to 4.2, some of my unit tests have been breaking on an AssertConfigurationIsValid. I’ve now managed to cut down my classes to a minimum example necessary to reproduce the problem

Classes:

public abstract class BaseBaseSource {  }
public class BaseSource : BaseBaseSource {
    public string Foo { get; set; }
}
public class Source : BaseSource { }

public abstract class BaseBaseDest {
    public string Foo { get; set; }
}
public class BaseDest : BaseBaseDest {  }
public class Dest : BaseDest { }

Mapping Profile:

public class TestProfile : Profile {
    protected override void Configure() {
        CreateMap<BaseSource, BaseDest>();
        CreateMap<Source, Dest>()
            .IncludeBase<BaseSource, BaseDest>();
    }
}

Unit Test:

[TestMethod]
public void IncludeBase_AutoMapper42() {
    var config = new MapperConfiguration(cfg => cfg.AddProfile<TestProfile>());
    config.AssertConfigurationIsValid();
}

// [TestMethod]
// public void IncludeBase_AutoMapper41() {
//  Mapper.Initialize(cfg => cfg.AddProfile<TestProfile>());
//  Mapper.AssertConfigurationIsValid();
// }

Mapping failure error message:

BaseBaseSource -> BaseBaseDest (Destination member list) AutoMapper42.BaseBaseSource -> AutoMapper42.BaseBaseDest (Destination member list)

Unmapped properties: Foo

This test fails in AutoMapper 4.2, but passes in 4.1.1. To reproduce this, it seems to require multiple levels of inheritance, and for the property being matched NOT to be at the same level. For example, if you move Foo fo BaseBaseSource, the property is at the same level and the mapping works.

The problem disappears if you remove .IncludeBase (which in this case works because Foo is the same on both sides, but my full example requires mapping statements).

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Boychenkocommented, Feb 19, 2016

Looks like I’ve found issue related to this one. If it’s not related I’ll create separate one. Interesting that second map works without problems. Minimal example:

    [TestFixture]
    public class MappingTests
    {
        [Test]
        public void ShouldUseLevel0Mapping()
        {
            var config = new MapperConfiguration(
                cfg =>
                {
                    cfg.AddProfile<TestProfile>();
                });
            config.AssertConfigurationIsValid();
        }

        public class SourceLevel0
        {
        }

        public class DestinationLevel0
        {
            public int Ignored { get; set; }
        }

        public class DestinationLevel1 : DestinationLevel0
        {
        }

        public class SourceLevel1 : SourceLevel0
        {
        }

        public class SourceLevel2 : SourceLevel1
        {
        }

        public class TestProfile : Profile
        {
            protected override void Configure()
            {
                CreateMap<SourceLevel0, DestinationLevel1>()
                    .ForMember(x => x.Ignored, o => o.Ignore());
                CreateMap<SourceLevel1, DestinationLevel1>()
                    .IncludeBase<SourceLevel0, DestinationLevel1>();
                CreateMap<SourceLevel2, DestinationLevel1>()
                    .IncludeBase<SourceLevel1, DestinationLevel1>();
            }
        }
    }
0reactions
lock[bot]commented, May 7, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

5b4410e59b62eea4449fdb3e8b...
Implement RSA-PSS SSLPrivateKey for Android >= N. Starting Android N, RSA-PSS may be used. Prior to that, it doesn't work. If we ever...
Read more >
FNM BPM
Related intertie constraints (ITC) on market schedules are discussed in section 4.2.4.1. Unscheduled flow is managed by enforcing both physical flow limits and ......
Read more >
Safety, Health, and Environmental Standard
2 An inventory listing of all chemicals the outside contractor/subcontractor shall have on base to include base location and quantity. 4.2.4.2.3 ...
Read more >
dafi36-2110.pdf - Air Force - AF.mil
This instruction implements Air Force Policy Directive (AFPD) 36-21, Utilization and. Classification of Military Personnel, and DAFPD 36-26, ...
Read more >
DIVISION I MANUAL
4.1. Board of Governors. 18. 4.2. Division I Board of Directors. ... athletics standards required for such membership or failing to meet the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found