Hi everyone,
I ran into the following error tonight while attempting to use automapper to map a datetime field to a protobuf timestamp property:
To fix it, add the following to your mapping profile:
UPDATE:
I later hit a similar error parsing a different entity:
Entity-> EntityDto
EntityService.Models.Entity-> EntityService.EntityDto
Destination Member:
CreatedAt
—> System.ArgumentException: Conversion from DateTime to Timestamp requires the DateTime kind to be Utc (Parameter ‘dateTime’)
Implementing the following map appears to have resolved it:
If you’re planning to go the other way (timestamp -> datetime) you may also need the following:
I’m currently using the following base class in my library:
{
public BaseMappingProfile()
{
CreateMap().ConvertUsing(x => Timestamp.FromDateTime(DateTime.SpecifyKind(x, DateTimeKind.Utc)));
CreateMap().ConvertUsing(x => x.ToDateTime());
}
}
Google didn’t seem to turn up a lot so I thought I’d post it here in case it helps someone out!