I have an application that uses AutoMapper to convert certain classes to others. This continued to this day. The application was posted approximately 3 months. In the meantime, we performed several deployments in which the application was restarted, but IIS does not.
Out of nowhere, the application began to crash, looking back at the logs that we found out that this was the reason:
System.NullReferenceException: Object reference not set to an instance of an object.
at AutoMapper.Configuration.<>c__DisplayClass13.<FindExplicitlyDefinedTypeMap>b__12(TypeMap x)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at AutoMapper.Configuration.FindExplicitlyDefinedTypeMap(Type sourceType, Type destinationType)
at AutoMapper.Configuration.CreateTypeMap(Type source, Type destination, String profileName)
at AutoMapper.Configuration.CreateMap[TSource,TDestination](String profileName)
at AutoMapper.Configuration.CreateMap[TSource,TDestination]()
at AutoMapper.Mapper.CreateMap[TSource,TDestination]()
So, we switched to our backup server, which does not have this problem at all. We tried to fix the problem by restarting the application that did not help. Only restarting IIS fixed the problem.
, , , https://github.com/jbogard/AutoMapper/. , , ConfigurationStore AutoMapper.
private TypeMap FindExplicitlyDefinedTypeMap(Type sourceType, Type destinationType)
{
return _typeMaps.FirstOrDefault(x => x.DestinationType == destinationType && x.SourceType == sourceType);
}
_typeMaps .
private readonly IList<TypeMap> _typeMaps = new List<TypeMap>();
TypeMap, , x.DestionationType x.SourceType :
private readonly TypeInfo _destinationType;
private readonly TypeInfo _sourceType;
public Type SourceType
{
get { return _sourceType.Type; }
}
public Type DestinationType
{
get { return _destinationType.Type; }
}
, _sourceType / _destionationType !
- / - ?