2

I'm using AutoMapper 4.1.1 (latest stable release on NuGet), and it looks like using ReverseMap on an open generic CreateMap doesn't work.

Sample program:

static void Main(string[] args)
{
    //Mapper.CreateMap(typeof(A<>), typeof(B<>)).ReverseMap(); // Doesn't work.
    Mapper.CreateMap(typeof(A<>), typeof(B<>)); // Works.
    Mapper.CreateMap(typeof(B<>), typeof(A<>)); // Works.

    Mapper.CreateMap<AData, BData>().ReverseMap();

    var b = new B<BData> { Data = new BData { Info = "Test" } };
    var a = Mapper.Map<A<AData>>(b);
}

public class A<T>
{
    public T Data { get; set; }
}

public class B<T>
{
    public T Data { get; set; }
}

public class AData
{
    public string Info { get; set; }
}

public class BData
{
    public string Info { get; set; }
}

If I use the line with ReverseMap on it, I get the following exception:

Missing type map configuration or unsupported mapping.

Mapping types: B`1 -> A`1 ConsoleApplication64.Program+B`1[[ConsoleApplication64.Program+BData, ConsoleApplication64, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> ConsoleApplication64.Program+A`1[[ConsoleApplication64.Program+AData, ConsoleApplication64, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

Destination path: A`1

Source value: ConsoleApplication64.Program+B`1[ConsoleApplication64.Program+BData]

Am I doing something wrong, or can we actually not use ReverseMap with open generics?

zimdanen
  • 5,508
  • 7
  • 44
  • 89

0 Answers0