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.

After 4.2 ResolveUsing can't handle nulls.

See original GitHub issue

Sorry, I can’t get this to format everything as a code block, or even bolded. If you run this below in a console app you will see the error. There was another work item that seeming had to do with nullable of T. This is unrelated to that issue.

**Mapping types:
Object -> DestinationInner
System.Object -> ConsoleApplication2.Program+DestinationInner

Destination path:
Destination.Inner.Inner

Source value:
(null)
   at AutoMapper.MappingEngine.Map(ResolutionContext context)
   at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy
MapPropertyValue(ResolutionContext context, Object mappedObject, PropertyMap pr
pertyMap)**

`static void Main(string[] args)
{
    var mapper = new AutoMapper.MapperConfiguration(cfg =>
    {
        cfg.CreateMap<Source, Destination>()
            .ForMember(dest => dest.Inner, opt => opt.ResolveUsing(src => src.Inner));
        cfg.CreateMap<SourceInner, DestinationInner>();
    }).CreateMapper();

    var goodSource = new Source()
    {
        Inner = new SourceInner() { Name = "BillRob", },
    };
    var goodDestination = mapper.Map<Source, Destination>(goodSource);
    Console.WriteLine(goodDestination.Inner.Name);

    var nullSource = new Source();
    var nullDestination = mapper.Map<Source, Destination>(nullSource);
    //exception thrown.
}

public class Source
{
    public Source()
    {               
    }

    public SourceInner Inner { get; set; }
}

public class SourceInner
{
    public string Name { get; set; }
}

public class Destination
{
    public DestinationInner Inner { get; set; }
}

public class DestinationInner
{
    public string Name { get; set; }
}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jbogardcommented, May 9, 2016

And I’m just waiting on .NET Core RC2 to drop.

SOON.gif

On Mon, May 9, 2016 at 3:43 PM, Mac notifications@github.com wrote:

@lbargaoanu https://github.com/lbargaoanu I can’t get any update from https://www.myget.org/F/automapperdev/api/v2. So I can’t wait for the official (or beta) release to be out! [image: 😉]

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/AutoMapper/AutoMapper/issues/1123#issuecomment-217867456

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

Automapper resolveusing not returning nulls
Using LinqPad and AutoMapper 2.2.1 the following gives me a valid date when KeyValue has a date, and a null DateTime when KeyValue...
Read more >
TSConfig Reference - Docs on every TSConfig option
An error occurs if any of the files can't be found. ... since these import paths would not be resolvable at runtime in...
Read more >
In AutoMapper 8.0 missing ResolveUsing
In this case you have to extract it to a method (Func) or do it inline if you can. Also, null propagation isn't...
Read more >
AutoMapper Documentation
9.1 Handling null collections. When mapping a collection property, if the source value is null AutoMapper will map the destination field to ...
Read more >
Chapter 9. Issues Resolved in Fuse 7.0
9.1. Apache Karaf container issues resolved in Fuse 7.0 ; KARAF-1143. Karaf (Config Mbean) can not recognize the features when Karaf installation path...
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