AutoMapper: InvalidOperationException : ValueFactory attempted to access the Value property of this instance.
This issue was introduced to us after updating to version 5.2.0.
We have a test helper which creates our mapper and adds profiles for us via reflection (we also tried to wrap it with a lock).
private static IMapper MapAutoMapper()
{
lock (new object())
{
var profiles = from assembly in AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.StartsWith("ProjectName."))
from profileType in assembly.GetExportedTypes()
where typeof(Profile).IsAssignableFrom(profileType) && !profileType.GetTypeInfo().IsAbstract
select (Profile)Activator.CreateInstance(profileType);
var config = new MapperConfiguration(cfg =>
{
foreach (var profile in profiles)
{
cfg.AddProfile(profile);
}
});
return config.CreateMapper();
}
}
This often throws the exception down below on our build server (TeamCity). This should be related to a multi-threading issue as Lazy<> is involved which is not thread-safe, right?
System.InvalidOperationException : ValueFactory attempted to access the Value property of this instance.
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at AutoMapper.Mappers.ConvertMapper.MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
at AutoMapper.Execution.TypeMapPlanBuilder.MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, TypePair typePair, Expression sourceParameter, Expression contextParameter, PropertyMap propertyMap, Expression destinationParameter)
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(Expression destinationFunc, Boolean constructorMapping)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda()
at AutoMapper.TypeMap.Seal(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider)
at AutoMapper.MapperConfiguration.Seal()
at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression, IEnumerable`1 mappers)
at AutoMapper.MapperConfiguration..ctor(Action`1 configure)
at Shared.TestHelper.WithFakes.MapAutoMapper() in C:\Something\Something\Project\Path\WithFakes.cs:line xx
Any ideas?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (16 by maintainers)
We’ve got a pending PR for this one.
On Thu, Dec 15, 2016 at 9:58 PM, Cindy notifications@github.com wrote:
Updating to the latest stable release 6.0.2 fixed my solution. Just wanted to say great work.
Try the MyGet build.