Hi folks,
I'm upgrading from a working version 3 to 5 with a ridiculous number of maps defined, so I won't bother to post them here.
I've moved my staticy configs into profiles, and then included them like this.
public static MapperConfiguration Configure()
{
var mappings = new MapperConfiguration(config =>
{
config.AddProfile<MapperConfigDomain>();
config.AddProfile<MapperConfigModels>();
config.AddProfile<MapperConfigDTO>();
config.AddProfile<MapperConfigExternalServices>();
});
return mappings;
}
Then moved all of the random CreateMap calls that had been leaked all over into the expected locations.
I'm finally in a compiling state.
But when I try to load the configuration to run a unit test I get
{"Property xxx is not defined for type yyy"}
Now, the problem is, that it absolutely exists. At first I thought it was because of a nullable type, but then I completely commented that out as a test and it went on to complain about a bool.
The properties are named exactly the same and are there across all objects. Have any of you encountered this? It does seem like maybe it has something to do with mappings from an interface to a concrete?
Did something change with how this works?
For example..
CreateMap<ApplicationVehicleModel, ApplicationVehicle>().ReverseMap();
CreateMap<IApplicationVehicleModel, ApplicationVehicle>()
.ForMember(dest => dest.Id, opt => opt.Ignore()).ReverseMap();
CreateMap<ApplicationVehicleModel, VehicleViewModel>().ReverseMap();
CreateMap<ApplicationVehicle, VehicleViewModel>().ReverseMap();
CreateMap<IVehicleModel, Vehicle>()
.ForMember(dest => dest.Id, opt => opt.Ignore())
.ForMember(dest => dest.ClientId, opt => opt.Condition(x => x.ClientId > 0))
.ReverseMap()
.ForMember(dest => dest.Id, opt => opt.Ignore())
.ForMember(dest => dest.ClientId, opt => opt.Condition(x => x.ClientId > 0));
When MapperConfiguration returns I get the following error
{"Property 'Boolean IsExotic' is not defined for type 'Web.Models.VehicleViewModel'"}
public class ApplicationVehicleModel : VehicleViewModel, IApplicationHeaderModel, IApplicationVehicleModel
public class VehicleViewModel {
public bool IsExotic { get; set; }
...
}
public class ApplicationVehicle {
public bool IsExotic { get; set; }
...
}
public interface IVehicleModel{
bool IsExotic { get; set; }
...
}
public class Vehicle {
public bool IsExotic { get; set; }
}