Nullable types mapping
See original GitHub issueHello! I’ve upgraded Autompapper from 3.1.0 to 4.2.1 and starting getting the exceptions in mappings like
cfg.CreateMap<Source, Destination>(). ForMember(dest => dest.NullableProp, opt => opt.ResolveUsing(src => src.Prop>0 ? src.Prop : (int?) null));
Source and Destination classes are simply:
public class Source
{
public int Prop { get; set; }
}
public class Destination
{
public int? NullableProp { get; set; }
}
Exception message:
Missing type map configuration or unsupported mapping.
Mapping types: Object -> Nullable
1 System.Object -> System.Nullable
1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]Destination path: Destination.NullableProp.NullableProp
Source value: (null)
Stack trace:
at AutomapperNullable.Program.Main(String[] args) in c:\Users\pzybenkov\Test\AutomapperNullable\AutomapperNullable\Program.cs:line 36 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
By the way in this simple test case there is a workaround to simply replace ResolveUsing with MapFrom, but obviously it is not always possible in real project.
By the way
cfg.CreateMap<Source, Destination>(). ForMember(dest => dest.NullableProp, opt => opt.ResolveUsing(src => src.Prop);
works fine.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
😃 Ok. Looking forward for realease with fix. By the way looks like v4.1.1 is the latest free from this issue
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.