Skip to content

Confusing exception when trying top map types with in parameters in ctor #4502

@Biotronic

Description

@Biotronic

Full Gist

https://gist.github.com/Biotronic/a58e42bde29f2208cd8958082c45d9d5

Source/destination types

public class Class1
{
    public TimeSpan X { get; set; }
}
public class Class2
{
    public Class2(in TimeSpan x)
    {
    }
}

Mapping configuration

        var config = new MapperConfiguration(cfg => { cfg.CreateMap<Class1, Class2>(); });

Version: 13.0.1

Expected behavior

Either for the mapping to just work, or an understandable error message to be displayed.

Something like 'AutoMapper cannot map in parameters (parameter x in Class2.ctor)'

Actual behavior

System.ArgumentException: Type must not be ByRef (Parameter 'type')

With an opaque call stack that says very little about what's actually wrong.

Steps to reproduce

Just run the Gist

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions