You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a small unit test that reproduces the issue (It throws a AutoMapperMappingException):
Mapper.Reset();
Mapper.CreateMap<ItemToMap, ItemToMapDto>();
Mapper.CreateMap<Tag, TagDto>();
var tag = new Tag() ;
List<ItemToMap> entities = new List<ItemToMap>();
for (int i = 0; i < 10; i++)
{
entities.Add(new ItemToMap()
{
Name = Guid.NewGuid().ToString(),
Tag = tag,
});
}
var dto = Mapper.Map<List<ItemToMap>, List<ItemToMapDto>>(entities);
Here are the classes
public class ItemToMapDto
{
public ItemToMapDto()
{
/* Remove the line below and the mapping works correctly*/
this.Tag = new TagDto() { Name = Guid.NewGuid().ToString() };
}
public string Name { get; set; }
public TagDto Tag { get; set; }
}
public class TagDto
{
public string Name { get; set; }
public bool IsTrue { get; set; }
}
public class ItemToMap
{
public string Name { get; set; }
public Tag Tag { get; set; }
}
public class Tag
{
public string Name { get; set; }
public bool IsTrue { get; set; }
}
In AutoMapper version 1.1, in the PropertyMapMappingStrategy there was a check on UseDestinationValue to see whether to replace the existing value or not. Now it doesn't exist anymore.
When choosing the mapping strategy the method IsMatch returns False on the CacheMappingStrategy because DestinationValue is not null. But in the PropertyMapMappingStrategy, this same method crashes because a ResolutionContext with the same hash code already exists in the cache.
I don't have the problem anymore if I replace the line 111 in the file TypeMapObjectMapperRegistry.cs (PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, object mappedObject, PropertyMap propertyMap):
Here's a small unit test that reproduces the issue (It throws a AutoMapperMappingException):
Here are the classes
In AutoMapper version 1.1, in the PropertyMapMappingStrategy there was a check on UseDestinationValue to see whether to replace the existing value or not. Now it doesn't exist anymore.
When choosing the mapping strategy the method IsMatch returns False on the CacheMappingStrategy because DestinationValue is not null. But in the PropertyMapMappingStrategy, this same method crashes because a ResolutionContext with the same hash code already exists in the cache.
I don't have the problem anymore if I replace the line 111 in the file TypeMapObjectMapperRegistry.cs (PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, object mappedObject, PropertyMap propertyMap):
with this one:
The text was updated successfully, but these errors were encountered: