GenerateEntityFrameworkPrimaryKeyPropertyMaps throws null pointer exception
See original GitHub issueI’ve added AutoMapper.Collection and AutoMapper.Collection.EntityFramework to my project. But I’m getting a null pointer exception:
System.NullReferenceException: ‘Object reference not set to an instance of an object.’
My code is:
var mapperConfig = new MapperConfiguration(cfg =>
{
cfg.AddCollectionMappers();
cfg.SetGeneratePropertyMaps<GenerateEntityFrameworkPrimaryKeyPropertyMaps<PlaygroundContext>>();
...
}
All of my entities have ID properties and are attributed with [Key]
Stack Trace:
at AutoMapper.EquivalencyExpression.EquivalentExpressions.<>c.<CreateEquivalentExpression>b__11_1(PropertyMap pm)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at AutoMapper.EquivalencyExpression.EquivalentExpressions.CreateEquivalentExpression(IEnumerable`1 propertyMaps)
at AutoMapper.EquivalencyExpression.EquivalentExpressions.<>c__DisplayClass7_0.<GetEquivalentExpression>b__1(IGeneratePropertyMaps _)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at AutoMapper.EquivalencyExpression.EquivalentExpressions.<>c__DisplayClass7_0.<GetEquivalentExpression>b__0(TypePair tp)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at AutoMapper.EquivalencyExpression.EquivalentExpressions.GetEquivalentExpression(IConfigurationProvider configurationProvider, TypeMap typeMap)
at AutoMapper.EquivalencyExpression.EquivalentExpressions.GetEquivalentExpression(IConfigurationObjectMapper mapper, Type sourceType, Type destinationType)
at AutoMapper.Mappers.EquivalentExpressionAddRemoveCollectionMapper.IsMatch(TypePair typePair)
at AutoMapper.MapperConfiguration.<>c__DisplayClass69_0.<FindMapper>b__0(IObjectMapper m)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at AutoMapper.MapperConfiguration.FindMapper(TypePair types)
at AutoMapper.MapperConfiguration.GetTypeMap(TypePair initialTypes)
at AutoMapper.LockingConcurrentDictionary`2.<>c__DisplayClass2_1.<.ctor>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at AutoMapper.MapperConfiguration.ResolveTypeMap(TypePair typePair, ITypeMapConfiguration inlineConfiguration)
at AutoMapper.MapperConfiguration.ResolveTypeMap(TypePair typePair)
at AutoMapper.Execution.TypeMapPlanBuilder.<>c__DisplayClass17_0.<CheckForCycles>g__ResolveTypeMap|6(TypePair types)
at AutoMapper.Execution.TypeMapPlanBuilder.<>c__DisplayClass17_0.<CheckForCycles>g__ResolvePropertyTypeMap|5(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.<>c__DisplayClass17_0.<CheckForCycles>b__1(PropertyMap pm)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at AutoMapper.Execution.TypeMapPlanBuilder.CheckForCycles(HashSet`1 typeMapsPath)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda(HashSet`1 typeMapsPath)
at AutoMapper.TypeMap.Seal(IConfigurationProvider configurationProvider)
at AutoMapper.MapperConfiguration.Seal()
at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression)
at AutoMapper.MapperConfiguration..ctor(Action`1 configure)
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Nullpointerexception throws when inserting entity using ...
I want to use generated endpoint to insert new object into datastore. But, an exception is throwing. fooEndpoint.insertFoo(foo); // throws null ...
Read more >AutoMapper
Collection and AutoMapper.Collection.EntityFramework to my project. But I'm getting a null pointer exception: System.NullReferenceException: 'Object reference ...
Read more >Automapper custom resolver throws null exception in ...
Hi,. We are using AutoMapper in our Commerce site. While mapping from the custom model to an EPiServer Model(VariationContent) throws a below error....
Read more >Why does this call to Trigger keySet() throw a null pointer ...
@Emilio I think the "works fine" in the question here just means no null pointer exception. The idSet will end up with only...
Read more >Adding a deep mapping causes a null pointer exception ...
My source class doesn't have a default construct (it's an immutable Joda Bean). Is this the cause? java.lang.NullPointerException. at com.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You might not be mapping all your Primary Keys to properties on your Model. All primary keys need to be mapped to the model, so that they can figure out if they are equal to each other by a unique identifier.
If that’s not the case can you provide a gist of it failing so I can replicate what’s going wrong?
hi, we got the same issue and it was as @TylerCarlson1 stated, an issue with our entity mapping to our contracts. Is it possible to improve the codebase to throw a more understandable exception at this point?