AssertConfigurationIsValid does not fail when mapping from nullable type to non-nullable type
See original GitHub issueSource/destination types
public class Source
{
public Guid? OptionalRelationId { get; set; }
}
public class Destination
{
public Guid OptionalRelationId { get; set; }
}
Mapping configuration
CreateMap<Source, Destination>();
Version: 8.1.0
Expected behavior
Mapper.AssertConfigurationIsValid();
throws an AutoMapperConfigurationException
Actual behavior
The configuration is asserted to be valid.
Steps to reproduce
class Program
{
static void Main(string[] args)
{
Mapper.Initialize(x => x.AddProfile<Mappings>());
try
{
Mapper.AssertConfigurationIsValid(); // Does not throw
}
catch (AutoMapperConfigurationException e)
{
Console.WriteLine(e);
throw;
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
c# - Automapper Mapping Exception despite ...
I am trying to get more diagnostic information to debug the actual problem. In the unit test I get a pass since no...
Read more >Mapper Help - Missing type map configuration or ...
3) My mappings are incorrect due to the mismatch values types. Example, mapping from a non-nullable type to a nullabletype and vise versa....
Read more >AutoMapper And Incompleteness
If a null slips through this could cause a crashing error. While AutoMapper has an AssertConfigurationIsValid method, it doesn't test for ...
Read more >AutoMapper Madness - Unit Testing Your Maps - Blog
This post delves into how I unit test AutoMapper and how I structure my tests to reduce code duplication as much as possible....
Read more >AutoMapper Madness - ReverseMap and Config Validation
ReverseMap Configs Are Not Tested By AssertConfigurationIsValid() ! ... Turns out, reverse maps aren't validated or checked by AutoMapper! This is ...
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 Free
Top 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
I disagree, I think the actual behavior fits with how AM works, trying to make the mapping work if there is a reasonable default. Most people want to ignore validations, not add new ones 😃 cc @jbogard
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.