abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.92k stars 3.45k forks source link

AutoMapper exception on startup after upgrade from 5.1 to 5.3.3 #13749

Closed gdunit closed 2 years ago

gdunit commented 2 years ago

Framework Version: 5.3.3 Database: SQL server

Upon upgrading from 5.1 to 5.3.3, I have encountered an exception on startup of the IdentityServer and HttpAPi.Host projects. Apart from the upgrade of the packages and changing a couple of defunct Blazorise enum values in the UI project, there have been no other changes made.

I have tried the following:

Here is the exception:

2022-08-19 13:29:17.791 +01:00 [ERR] An exception was thrown while activating Volo.Abp.BackgroundJobs.BackgroundJobStore -> Volo.Abp.ObjectMapping.DefaultObjectMapper1[[Volo.Abp.BackgroundJobs.AbpBackgroundJobsDomainModule, Volo.Abp.BackgroundJobs.Domain, Version=5.3.3.0, Culture=neutral, PublicKeyToken=null]] -> Volo.Abp.AutoMapper.AutoMapperAutoObjectMappingProvider1[[Volo.Abp.BackgroundJobs.AbpBackgroundJobsDomainModule, Volo.Abp.BackgroundJobs.Domain, Version=5.3.3.0, Culture=neutral, PublicKeyToken=null]] -> λ:Volo.Abp.AutoMapper.IMapperAccessor -> λ:Volo.Abp.AutoMapper.MapperAccessor. Autofac.Core.DependencyResolutionException: An exception was thrown while activating Volo.Abp.BackgroundJobs.BackgroundJobStore -> Volo.Abp.ObjectMapping.DefaultObjectMapper1[[Volo.Abp.BackgroundJobs.AbpBackgroundJobsDomainModule, Volo.Abp.BackgroundJobs.Domain, Version=5.3.3.0, Culture=neutral, PublicKeyToken=null]] -> Volo.Abp.AutoMapper.AutoMapperAutoObjectMappingProvider1[[Volo.Abp.BackgroundJobs.AbpBackgroundJobsDomainModule, Volo.Abp.BackgroundJobs.Domain, Version=5.3.3.0, Culture=neutral, PublicKeyToken=null]] -> λ:Volo.Abp.AutoMapper.IMapperAccessor -> λ:Volo.Abp.AutoMapper.MapperAccessor. ---> System.ArgumentException: An item with the same key has already been added. Key: AutoMapper.Internal.TypePair at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at AutoMapper.ProfileMap.<.ctor>gSetOpenTypeMapConfigs|5_9(<>c__DisplayClass5_0& ) at AutoMapper.ProfileMap..ctor(IProfileConfiguration profile, IGlobalConfigurationExpression configuration) at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression) at Volo.Abp.AutoMapper.AbpAutoMapperModule.CreateMappings(IServiceProvider serviceProvider) at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) at Autofac.Core.Activators.Delegate.DelegateActivator.b2_0(ResolveRequestContext ctxt, Action1 next) at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) --- End of inner exception stack trace --- at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Volo.Abp.BackgroundJobs.BackgroundJobWorker.DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) at Volo.Abp.BackgroundJobs.BackgroundJobWorker.DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) at Volo.Abp.BackgroundWorkers.AsyncPeriodicBackgroundWorkerBase.DoWorkAsync()`

Having tried various things, I am struggling to work out what might be the root cause. Could this be to do with the Automapper upgrade, or might something else be happening?

gdunit commented 2 years ago

OK, so this was (of course) my fault and nothing to do with ABP.. the problem turned out to be that I had accidentally tried to map the same type twice in one of the automapper profile files. This did not throw in earlier versions of AutoMapper but I guess it does in V11.