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.

Nullable types mapping

See original GitHub issue

Hello! 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 -> Nullable1 System.Object -> System.Nullable1[[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:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pavel-zybenkovcommented, Mar 2, 2016

😃 Ok. Looking forward for realease with fix. By the way looks like v4.1.1 is the latest free from this issue

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 Problem when creating mapping conditions ...
So, it tells me that AutoMapper completely disregards value type's nullability and just uses base default types on map, which makes me trouble, ......
Read more >
Working with nullable reference types - EF Core
C# 8 introduced a new feature called nullable reference types (NRT), allowing reference types to be annotated, indicating whether it is ...
Read more >
Documentation - Advanced Types
Nullable types. TypeScript has two special types, null and undefined , that have the values null and undefined respectively. We mentioned these briefly...
Read more >
Non-nullable reference types and automapper : r/csharp
Trying to implement non-nullable reference types in a somewhat large codebase. Right now theres a lot of different people touching it, ...
Read more >
Mapping nullable does not use nullable map when called ...
Hi, After upgrading to 5.2.0 I am having issues with mapping nullables: A map configured for a nullable type does not seem to...
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