Olá!
Eu estou fazendo a aula "Mapeando objetos com o AutoMapper" dentro do "05. Melhorando o código" e o instrutor usou a versão 8.1.1 do Automapper. Mas a última versão disponível hoje é a 11.0.0.
Infelizmente deu erro em tudo ao processar no Postman e no Swagger ...
... fui pesquisar a documentação do Automapper e para minha surpresa encontrei o texto:
==========================================================
11.0 Upgrade Guide / 11.0 Guia de atualização
AutoMapper now targets .Net Standard 2.1 and doesn’t work on .Net Framework
O AutoMapper agora tem como alvo o .Net Standard 2.1 e não funciona no .Net Framework
==========================================================
Isso quer dizer que miou tudo, pois o instrutor está usando o ".Net 5"? (eu estou usando o ".Net 6")
Bom... o projeto NÃO tem nenhum erro na lista de erros, então decidi fazer um "downgrade" de versão:
Eu acreditei que funcionaria numa boa, mas infelizmente apresentou o mesmo erro:
==========================================================
System.MissingMethodException: Cannot dynamically create an instance of type 'FilmesAPI.Profiles.FilmeProfile'. Reason: No parameterless constructor defined.
at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type)
at AutoMapper.Configuration.MapperConfigurationExpression.AddProfile(Type profileType)
at AutoMapper.Configuration.MapperConfigurationExpression.AddMapsCore(IEnumerable1 assembliesToScan)
at AutoMapper.Configuration.MapperConfigurationExpression.AddMaps(Assembly[] assembliesToScan)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c__DisplayClass12_0.<AddAutoMapperClasses>b__6(MapperConfigurationExpression options)
at Microsoft.Extensions.Options.ConfigureNamedOptions
1.Configure(String name, TOptions options)
at Microsoft.Extensions.Options.OptionsFactory1.Create(String name)
at Microsoft.Extensions.Options.UnnamedOptionsManager
1.get_Value()
at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c.b__12_2(IServiceProvider sp)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c.b__12_3(IServiceProvider sp)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
...
HEADERS
=======
Accept: /
Connection: keep-alive
Host: localhost:7189
User-Agent: PostmanRuntime/7.29.0
Accept-Encoding: gzip, deflate, br
Cache-Control: no-cache
Content-Type: application/json
Content-Length: 103
Postman-Token: a0bce2ff-a4a5-42ca-956b-9639b01e0253
==========================================================
Agradeço qualquer dica.
Obrigado,
[]'s,
Fabio I.