I'm trying to use Mapster to map an object from CcmApplication
to RpcCcmApplication
and getting the following exception:
TypeLoadException: Signature of the body and declaration in a method implementation do not match. Type: 'GeneratedType_1'. Assembly: 'Mapster.Dynamic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
My code is as follows (sorry for so many classes/interfaces but somehow if I reduce it it actually does work so this is the smallest example I can give):
public class Test
{
private readonly IMapper _mapper = new Mapper();
[Fact]
public void FailedTest()
{
var app = new CcmApplication() { DeploymentTypes = new[] { new CcmDeploymentType() { Name = "Test" } } };
var t = _mapper.Map<RpcCcmApplication>(app);
}
}
public interface ISystemProperties
{
}
public interface IBaseProperties
{
public ISystemProperties SystemProperties { get; init; }
}
public interface ICcmSoftwareBase : IBaseProperties
{
string? Name { get; init; }
}
public interface ICcmApplication : ICcmSoftwareBase
{
IEnumerable<ICcmDeploymentType>? DeploymentTypes { get; init; }
}
public interface ICcmDeploymentType : ICcmSoftwareBase
{
}
public record SystemProperties : ISystemProperties
{
}
public abstract record BaseProperties : IBaseProperties
{
public ISystemProperties SystemProperties { get; init; } = null!;
}
public record CcmSoftwareBase : BaseProperties, ICcmSoftwareBase
{
public string? Name { get; init; }
}
public record CcmApplication : CcmSoftwareBase, ICcmApplication
{
public IEnumerable<ICcmDeploymentType>? DeploymentTypes { get; init; }
}
public record CcmDeploymentType : CcmSoftwareBase, ICcmDeploymentType
{
}
public record RpcSystemProperties : ISystemProperties
{
}
public abstract record RpcBaseProperties : IBaseProperties
{
public ISystemProperties SystemProperties { get; init; } = null!;
}
public record RpcCcmSoftwareBase : RpcBaseProperties, ICcmSoftwareBase
{
public string? Name { get; init; }
}
public record RpcCcmApplication : RpcCcmSoftwareBase, ICcmApplication
{
public IEnumerable<ICcmDeploymentType>? DeploymentTypes { get; init; }
}
public record RpcCcmDeploymentType : RpcCcmSoftwareBase, ICcmDeploymentType
{
}
What I've noticed is that if ICcmDeploymentType
does not implement ICcmSoftwareBase
then it works, not sure what I'm missing here.