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.

AssertConfigurationIsValid does not fail when mapping from nullable type to non-nullable type

See original GitHub issue

Source/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:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lbargaoanucommented, May 7, 2019

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

0reactions
lock[bot]commented, Jul 3, 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

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 >

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