-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Mapping an object that contains a nullable property which contains null throws an AutoMapperMappingException with the following message:
Error mapping types.
Mapping types:
In -> Out
Workheld.Core.In -> Workheld.Core.OutType Map configuration:
In -> Out
Workheld.Core.In -> Workheld.Core.OutProperty:
B
The inner exception says
Non-static method requires a target.
This happens only when building in Debug mode, meaning when the Compile with .NET Native tool chain compiler option is not checked. When using .NET Native tool chain, the mapping works and produces the expected result. Also, when using AutoMapper 5.1.1, the mapping works.
To reproduce, create a Portable Class Library targeting:
- .NET Framework 4.5
- Windows 8
- APS.NET Core 1.0
- Windows Phone 8.1
- Xamarin.Android
- Xamarin.iOS
- Xamarin.iOS (Classic)
- Xamarin.Mac
(Profile111) that references the AutoMapper 6.0.1 NuGet package, and add the following classes:
public class In
{
public int? A { get; set; }
public int? B { get; set; }
}
public class Out
{
public int? A { get; set; }
public int? B { get; set; }
}
public static class TestClass
{
public static Out TestMethod()
{
Mapper.Initialize(c =>
{
c.CreateMap<In, Out>();
});
var input = new In
{
A = 123
};
return Mapper.Map<In, Out>(input);
}
}
Then, create a blank UWP app project that references the PCL and calls the TestMethod. Run it in Debug and Release mode, and watch the different behavior.