title: AutoMapper on .Net Core 3.1
body: <p>In a Net Core 3.1 application i' m trying to use the AutoMapper.Extensions.Microsoft.DependencyInjection 7.
  In solution i have 3 projects:</p>
  
  <ul>
  <li>Content (start project)</li>
  <li>Core</li>
  <li>Entity framework</li>
  </ul>
  
  <p>After nuget installation, this is my code:</p>
  
  <p>Startup.cs in Content Project:</p>
  
  <pre><code>using AutoMapper;
  using Project.Content.EntityFrameWork;
  using Project.Content.Dto;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  
  namespace Project.Content
  {
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddControllers();
              // Auto Mapper Configurations
              services.AddAutoMapper(typeof(AutoMapping));
  
              string connectionString = Configuration["ConnectionString:Default"];
              services.AddDbContext&lt;ProjectContext&gt;(options =&gt;
          options.UseSqlServer(connectionString));
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseHttpsRedirection();
  
              app.UseRouting();
  
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
      }
  }
  </code></pre>
  
  <p>AutoMapping.cs in Content project:</p>
  
  <pre><code>using AutoMapper;
  using Project.Content.Core.Domain.Model;
  
  namespace Project.Content.Dto
  {
      class AutoMapping : Profile
      {
          public AutoMapping()
          {
              CreateMap&lt;Exercise, ExerciseDto&gt;();
              CreateMap&lt;ExerciseDto, Exercise&gt;();
          }
      }
  }
  </code></pre>
  
  <p>And this is the Controller where I'm trying to map:</p>
  
  <pre><code>using AutoMapper;
  using Project.Content.EntityFrameWork;
  using Project.Content.Dto;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Logging;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  
  namespace Project.Content.Controllers
  {
      [ApiController]
      [Route("/exercise")]
      public class ExercisesController : ControllerBase
      {
          private readonly ILogger&lt;ExercisesController&gt; _logger;
          private ProjectContext _dbContext;
          private IMapper _mapper;
  
          public ExercisesController(ILogger&lt;ExercisesController&gt; logger, ProjectContext dbContext, IMapper mapper)
          {
              _logger = logger;
              _dbContext = dbContext;
              _mapper = mapper;
          }
  
          [HttpGet("{id}")]
          public ExerciseDto GetById(int id)
          {
  
              var exercise =  _mapper.Map&lt;ExerciseDto&gt;(_dbContext.Exercises.Where(x =&gt; x.Id == id));
              return exercise;
          }
      }
  }
  </code></pre>
  
  <p>In this controller when it tries to map objects it shows the error:</p>
  
  <blockquote>
    <p>AutoMapper.AutoMapperMappingException: Missing type map configuration
    or unsupported mapping.</p>
    
    <p>Mapping types: EntityQueryable<code>1 -&gt; ExerciseDto
    Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable</code>1[[Project.Content.Core.Domain.Model.Exercise,
    Project.Content.Core, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=null]] -> Project.Content.Dto.ExerciseDto    at
    lambda_method(Closure , EntityQueryable`1 , ExerciseDto ,
    ResolutionContext )    at lambda_method(Closure , Object , Object ,
    ResolutionContext )    at
    Project.Content.Controllers.ExercisesController.GetById(Int32 id) in
    C:\Projects\Project\Project.Content\Project.Content.Service\Controllers\ExercisesController.cs:line
    44    at lambda_method(Closure , Object , Object[] )    at
    Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object
    target, Object[] parameters)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper
    mapper, ObjectMethodExecutor executor, Object controller, Object[]
    arguments)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State&amp;
    next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
    --- End of stack trace from previous location where exception was thrown ---    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed
    context)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State&amp;
    next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
    --- End of stack trace from previous location where exception was thrown ---    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker
    invoker, Task lastTask, State next, Scope scope, Object state, Boolean
    isCompleted)    at
    Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker
    invoker)    at
    Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint
    endpoint, Task requestTask, ILogger logger)    at
    Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext
    context)    at
    Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext
    context)</p>
  </blockquote>