title: ASP.NET Core - AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping
body: <p>In my ASP.NET Core Web API, I have IdentityDbContext:</p>
  <pre><code>public class MyDbContext : IdentityDbContext&lt;ApplicationUser, ApplicationRole, long, IdentityUserClaim&lt;long&gt;, ApplicationUserRole, IdentityUserLogin&lt;long&gt;, IdentityRoleClaim&lt;long&gt;, IdentityUserToken&lt;long&gt;&gt;
  {
      public MyDbContext(DbContextOptions&lt;MyDbContext&gt; options)
          : base(options)
      {
      }
  
      public DbSet&lt;ApplicationRole&gt; ApplicationRole { get; set; }
      public DbSet&lt;ApplicationUserRole&gt; ApplicationUserRole { get; set; }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
  
          builder.Entity&lt;ApplicationUser&gt;(entity =&gt;
          {
              entity.Property(u =&gt; u.Id).ValueGeneratedOnAdd();
              entity.HasIndex(u =&gt; u.Email).IsUnique();
              entity.HasIndex(u =&gt; u.UserName).IsUnique();
          });
          builder.Entity&lt;ApplicationRole&gt;(entity =&gt;
          {
              entity.Property(r =&gt; r.Id).ValueGeneratedOnAdd();
              entity.HasIndex(r =&gt; r.Name).IsUnique();
          });
  }
  </code></pre>
  <p>IdentityModel:</p>
  <pre><code> public class ApplicationUser : IdentityUser&lt;long&gt;
   {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string MobileNumber { get; set; }
  
      [JsonIgnore]
      public bool? IsDeleted { get; set; }
      public DateTime? LastLogin { get; set; }
      public ICollection&lt;ApplicationUserRole&gt; UserRoles { get; set; }
   }
  
   public class ApplicationRole : IdentityRole&lt;long&gt;
   {
      public ICollection&lt;ApplicationUserRole&gt; UserRoles { get; set; }
   }
  
   public class ApplicationUserRole : IdentityUserRole&lt;long&gt;
   {
      public override long UserId { get; set; }
      public override long RoleId { get; set; }
      public virtual ApplicationUser User { get; set; }
      public virtual ApplicationRole Role { get; set; }
   }
  } 
  </code></pre>
  <p>LoginRequestDto:</p>
  <pre><code>public class LoginRequestDto
  {
      [Required]
      [JsonProperty(PropertyName = &quot;username&quot;)]
      public string UserName { get; set; }
  
      [Required(ErrorMessage = &quot;The password is required!&quot;)]
      public string Password { get; set; }
  }
  </code></pre>
  <p>UserDto:</p>
  <pre><code>public class UserDto
  {
      public long Id { get; set; }
      public string Firstname { get; set; }
      public string Lastname { get; set; }
      public string Email { get; set; }
      public string UserName { get; set; }
      public string MobileNumber { get; set; }
      public DateTime LastLogin { get; set; }
  }
  </code></pre>
  <p>AuthMapper:</p>
  <pre><code>public class AuthMapperProfile : Profile
  {
      public AuthMapperProfile()
      {
          CreateMap&lt;ApplicationUser, UserDto&gt;();
  
  }
  </code></pre>
  <p>Services:</p>
  <pre><code>public interface IAuthService
  {
      Task&lt;GenericResponseDto&lt;object&gt;&gt; LoginUser(LoginRequestDto request);
  }
  
  public class AuthService : IAuthService
  {
      private readonly UserManager&lt;ApplicationUser&gt; _userManager;
      private readonly RoleManager&lt;ApplicationRole&gt; _roleManager;
      private readonly IConfiguration _configuration;
      private readonly IMapper _mapper;
      private readonly MyDbContext _context;
  
      public AuthService(
          UserManager&lt;ApplicationUser&gt; userManager,
          RoleManager&lt;ApplicationRole&gt; roleManager,
          IConfiguration configuration,
          IMapper mapper,
          MyDbContext context
  
      )
      {
          _userManager = userManager;
          _roleManager = roleManager;
          _configuration = configuration;
          _mapper = mapper;
          _context = context;
      }
  
      public async Task&lt;GenericResponseDto&lt;object&gt;&gt; LoginUser(LoginRequestDto request)
      {
          var user = await _userManager.FindByNameAsync(request.UserName);
          var response = new GenericResponseDto&lt;object&gt;();
  
          if (user != null &amp;&amp; await _userManager.CheckPasswordAsync(user, request.Password))
          {
              var roles = await _userManager.GetRolesAsync(user);
              var authClaims = new List&lt;Claim&gt;
              {
                  new Claim(ClaimTypes.Name, user.UserName),
                  new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
              };
              foreach (var userRole in roles)
              {
                  authClaims.Add(new Claim(ClaimTypes.Role, userRole));
              }
              var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration[&quot;JWT:Secret&quot;]));
              var token = new JwtSecurityToken(
                  issuer: _configuration[&quot;JWT:ValidIssuer&quot;],
                  audience: _configuration[&quot;JWT:ValidAudience&quot;],
                  expires: DateTime.Now.AddHours(3),
                  claims: authClaims,
                  signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
              );
  
              response.Result = new
              {
                  token = new JwtSecurityTokenHandler().WriteToken(token),
                  user = _mapper.Map&lt;UserDto&gt;(user),
                  expires = token.ValidTo
              };
              response.StatusCode = 200;
              user.LastLogin = DateTime.Now;
              try
              {
                  await _context.SaveChangesAsync();
              }
              catch (Exception ex)
              {
                  response.Error = new ErrorResponseDto() { ErrorCode = 500, Message = ex.Message };
              }
              return response;
          }
  
          response.StatusCode = 400;
          response.Error = new ErrorResponseDto { ErrorCode = 400, Message = &quot;Invalid Username or Password!&quot; };
  
          return response;
      }
  }
  </code></pre>
  <p>I got this error:</p>
  <blockquote>
  <p>AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.</p>
  </blockquote>
  <blockquote>
  <p>Mapping types:
  Object -&gt; UserDto
  System.Object -&gt; DDM.API.Core.DTOs.v1.Authentication.UserDto
  at lambda_method198(Closure , Object , UserDto , ResolutionContext )
  at DDM.API.Core.Services.v1.Concrete.AuthService.LoginUser(LoginRequestDto request) in C:\Users\MyApp\Core\Services\v1\Concrete\AuthService.cs:line 78</p>
  </blockquote>
  <p>This is line 78:</p>
  <blockquote>
  <p>response.Result = new</p>
  </blockquote>
  <p>startup.cs:</p>
  <pre><code>  // Auto mapper
    services.AddAutoMapper(typeof(Startup));
  
    // Dependency Injection
    services.AddScoped&lt;IAuthService, AuthService&gt;();
  </code></pre>
  <p>controller:</p>
  <pre><code>    [Produces(&quot;application/json&quot;)]
      [HttpPost(&quot;login&quot;)]
      public async Task&lt;ActionResult&lt;GenericResponseDto&lt;object&gt;&gt;&gt; Login(LoginRequestDto loginRequest)
      {
          var response = await _authService.LoginUser(loginRequest);
          Response.StatusCode = response.StatusCode ?? StatusCodes.Status200OK;
          return new JsonResult(response);
      }
  </code></pre>
  <p>What do I do to resolve this?</p>
  <p>Thanks</p>