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.

`CreateMissingTypeMaps` doesn't work for destination object if source and destination types are the same

See original GitHub issue

Source/destination types

class A
{
    public string X { get; set; }
}

class B
{
    public string X { get; set; }
}

Mapping configuration

var config = new MapperConfiguration(cfg => cfg.CreateMissingTypeMaps = true)

Version: 5.1.1

Expected behavior

I pass an existing object to be filled. The type of source and destination objects are the same. I expect the destination object to be filled.

Actual behavior

The destination object is not filled. If I use a different destination type, it works fine. If I create a new object of the same type, it also works fine.

Steps to reproduce

var config = new MapperConfiguration(cfg => cfg.CreateMissingTypeMaps = true);
var mapper = config.CreateMapper();
var a1 = new A { X = "sample" };
var a2 = new A();
mapper.Map(a1, a2); // a2.X was not set, looks like a bug
var a3 = mapper.Map<A>(a1); // a3.X is set, ok

var b = new B();
mapper.Map(a1, b); // b.X is set, ok

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
llRandomcommented, Jun 5, 2017

I still don’t understand, is it some design limitation that blocks from implementing it or is there a logical reason why this particular case should not be supported?

0reactions
lock[bot]commented, May 6, 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

Automapper doesn't fill destination object
I use Automapper with CreateMissingTypeMaps option set to true . If I try to fill an existing object of the same type, it...
Read more >
AutoMapper — AutoMapper documentation
AutoMapper uses a convention-based matching algorithm to match up source to destination values. AutoMapper is geared towards model projection scenarios to ...
Read more >
AutoMapper Documentation
First, you need both a source and destination type to work with. The destination type's design can be influenced by.
Read more >
What is Automapper in C# and How to Use It
AutoMapper in C# is a library used to map data from one object to another in web development. It acts as a mapper...
Read more >
AutoMapper.xml 4.2.1
Use this method when the source and destination types are not known until runtime. </summary> <param name="source">Source object to map from</param>
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