Mapper.AssertConfigurationIsValid throws Mapper not initialized
Hi. I tried calling Mapper.AssertConfigurationIsValid on my project but it threw an exception. Aside from services.AddAutoMapper(typeof(Startup)) and a MappingProfile, what else am I missing? Thanks!
https://github.com/jbogard/ContosoUniversityCore/blob/07bb0f75a616881b7e513a25f6d0d6b4f0cf664c/src/ContosoUniversityCore/Startup.cs#L44
Exception details
System.InvalidOperationException
HResult=0x80131509
Message=Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.
Source=AutoMapper
StackTrace:
at AutoMapper.Mapper.get_Configuration()
at AutoMapper.Mapper.AssertConfigurationIsValid()
at Gldd.Api.Startup.ConfigureServices(IServiceCollection services) in C:\git\cutter-stripcharts-prototype\src\Gldd.Api\Startup.cs:line 36
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Gldd.Api.Program.Main(String[] args) in C:\git\cutter-stripcharts-prototype\src\Gldd.Api\Program.cs:line 10
The static API is going away - you need to resolve the mapper from the service collection.
On Tue, Jun 25, 2019 at 10:10 PM Jan Paolo Go [email protected] wrote:
Hi. I tried calling Mapper.AssertConfigurationIsValid on my project but it threw an exception. Aside from services.AddAutoMapper(typeof(Startup)) and a MappingProfile, what else am I missing? Thanks!
https://github.com/jbogard/ContosoUniversityCore/blob/07bb0f75a616881b7e513a25f6d0d6b4f0cf664c/src/ContosoUniversityCore/Startup.cs#L44
Exception details
System.InvalidOperationException HResult=0x80131509 Message=Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance. Source=AutoMapper StackTrace: at AutoMapper.Mapper.get_Configuration() at AutoMapper.Mapper.AssertConfigurationIsValid() at Gldd.Api.Startup.ConfigureServices(IServiceCollection services) in C:\git\cutter-stripcharts-prototype\src\Gldd.Api\Startup.cs:line 36 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection) at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services) at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services) at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider() at Microsoft.Extensions.Hosting.HostBuilder.Build() at Gldd.Api.Program.Main(String[] args) in C:\git\cutter-stripcharts-prototype\src\Gldd.Api\Program.cs:line 10
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbogard/ContosoUniversityCore/issues/35?email_source=notifications&email_token=AAAZQMSK7YSIRAOKXW5EYMTP4LM2VA5CNFSM4H3OBKT2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G3WJQYA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZQMXZDYAVMPWVJSOIJ5TP4LM2VANCNFSM4H3OBKTQ .