C# 尽管AssertConfigurationsValid()成功,但自动映射异常
我真是摸不着头脑。我已经从Automapper 2.2.1升级到了3.1.1,代码在崩溃之前仍然有效。我正在尝试获取更多诊断信息以调试实际问题 在单元测试中,我通过了测试,因为没有出现错误C# 尽管AssertConfigurationsValid()成功,但自动映射异常,c#,wcf,automapper-3,C#,Wcf,Automapper 3,我真是摸不着头脑。我已经从Automapper 2.2.1升级到了3.1.1,代码在崩溃之前仍然有效。我正在尝试获取更多诊断信息以调试实际问题 在单元测试中,我通过了测试,因为没有出现错误 [TestClass] public class TestOldWcfEndpoint { public TestContext TestContext { get; set; } bool FieldWasSpecified; [TestInitialize] publi
[TestClass]
public class TestOldWcfEndpoint
{
public TestContext TestContext { get; set; }
bool FieldWasSpecified;
[TestInitialize]
public void TestInitialize()
{
AutoMapperUnity.RegistrationInUnitTesting();
this.FieldWasSpecified = true;
}
[TestMethod]
public void Test_OldWcfHosting_AutomapperConfigurationIsValid()
{
try
{
AutoMapper.Mapper.AssertConfigurationIsValid();
}
catch (AutoMapper.AutoMapperMappingException aex)
{
this.TestContext.WriteLine(aex.Message);
throw;
}
}
}
AutoMapperUnity是一个静态帮助器类,用于连接到Unity容器:
public static class AutoMapperUnity
{
private static void Regsitrations()
{
Mapper.Reset();
var business = new BusinessLogicMaps(); business.Configure();
var api = new ApiServiceMaps(); api.Configure();
var wcf = new OldWcfMaps(); wcf.Configure();
Mapper.Configuration.AllowNullCollections = true;
}
public static void Registration(IUnityContainer container)
{
Regsitrations();
container.RegisterType<IMappingEngine>(new InjectionFactory(_ => Mapper.Engine));
container.RegisterType<IConfiguration>(new InjectionFactory(_ => Mapper.Configuration));
container.RegisterType<IConfigurationProvider>(new InjectionFactory(_ => Mapper.Configuration));
}
}
仅凭以上几点,我不知道它在更好地排除故障方面究竟失败了什么。DTO层还映射到业务对象等价物。我错过了一些非常重要的东西。当我解析Wcf特定的DTO时,它是从单元测试项目中获取它们的,该项目是代理客户端,而不是服务器主机项目 此错误是正确的,因为Proxy.CodeTypeWcfDTO!=OldWcf.CodeTypeWcfDTO 如果您遇到了这个问题,请务必检查您的NAMSpace,确保您正在查看正确的合同
public class OldWcfMaps
{
void CreateMapForCodes()
{
Mapper.CreateMap<CodeTypeDTO, CodeTypeWcfDTO>()
.ForMember(s => s.IDSpecified, o => o.Ignore());
Mapper.CreateMap<CodeTypeWcfDTO, CodeTypeDTO>();
Mapper.CreateMap<CodeDTO, CodeWcfDTO>()
.ForMember(s => s.ActiveSpecified, o => o.Ignore())
.ForMember(s => s.CodeTypeIDSpecified, o => o.Ignore())
.ForMember(s => s.IDSpecified, o => o.Ignore());
Mapper.CreateMap<CodeWcfDTO, CodeDTO>();
}
void CreateMapForCodeReports()
{
Mapper.CreateMap<CodeReportDTO, CodeReportWcfDTO>()
.ForMember(s => s.ActiveSpecified, o => o.Ignore())
.ForMember(s => s.AppIDSpecified, o => o.Ignore())
.ForMember(s => s.IDSpecified, o => o.Ignore())
.ForMember(s => s.CodeIDSpecified, o => o.Ignore())
Mapper.CreateMap<CodeReportWcfDTO, CodeReportDTO>();
}
void CreateMapForShiftReports()
{
this.CreateMapForCodeReports();
Mapper.CreateMap<ShiftReportDTO, ShiftReportWcfDTO>()
.ForMember(s => s.NumberOfReportsSpecified, o => o.Ignore());
Mapper.CreateMap<ShiftReportWcfDTO, ShiftReportDTO>();
}
public void Configure()
{
this.CreateMapForCodes();
this.CreateMapForShiftReports();
}
}
[ServiceBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class TimeClockServices : ITimeClockServices
{
/// <summary>
/// Reference to the AutoMapper Engine.
/// </summary>
private readonly IMappingEngine MapperEngine;
private readonly ILogFactory LogFactory;
private readonly ITimeClockDataService TimeClockApi;
public TimeClockServices(IMappingEngine mapper, ITimeClockDataService timeClockServices, ILogFactory logger)
{
this.MapperEngine = mapper;
this.TimeClockApi = timeClockServices;
this.LogFactory = logger;
}
public IEnumerable<CodeReportWcfDTO> GetCodeReports(ApplicationsEnum AppID, short DepartmentID, long CaseID, bool Active)
{
IEnumerable<CodeReportWcfDTO> groupOfWcfCodeReportDTOs = null;
try
{
// Get Data using shared internal interface.
IEnumerable<CodeReportDTO> codeReportDTOs =
this.TimeClockApi.GetCodeReports(AppID, DepartmentID, CaseID, Active);
// Convert the Data to the Wcf Extension Class.
// **OFFENDING LINE**
codeReportWcfDTOs =
this.MapperEngine.Map<IEnumerable<CodeReportDTO>, IEnumerable<CodeReportWcfDTO>>(codeReportDTOs);
}
catch (BLException bex)
{
throw new FaultException<BLExceptionFault>(
new BLExceptionFault("Business Engine Exception was thrown.", bex));
}
return codeReportWcfDTOs;
}
}
Missing type map configuration or unsupported mapping.
Mapping types:
CodeReportDTO -> CodeReportWcfDTO
Api.Contract.Entities.CodeReportDTO -> Legacy.Contracts.WcfDTO.CodeReportWcfDTO
Destination path:
IEnumerable`1[0]
Source value:
Api.Contract.Entities.CodeReportDTO