After 4.2 ResolveUsing can't handle nulls.
See original GitHub issueSorry, 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:
- Created 8 years ago
- Comments:17 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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.