Search code examples
c#asp.net-core.net-core

AutoMapper.AutoMapperMappingException: 'Missing type map configuration or unsupported mapping.' When I try to send a Post request to my API


When I try to send a post request to my API I get:

AutoMapper.AutoMapperMappingException: 'Missing type map configuration or unsupported mapping.'

I am trying to map one model to another to write to a database. See code below:

Posting to API URL with the below JSON:

{
  "UserId": 2,
  "Task": "test"
}
public class CreateTask
{
    [Required]
    public int UserId { get; set; }
    [Required]
    public string Task { get; set; }
}
public class Tasks
    {
        public int Id { get; set; }
        public int UserId { get; set; }
        public string Task { get; set; }
    }
[HttpPost("task")]
        public IActionResult CreateTask(CreateTask model)
        {
            _userService.CreateTask(model);
            return Ok(new { message = "Task Created" });
        }
public void CreateTask(CreateTask model)
        {

       private IMapper _mapper;



            // map model to new user object
            var blessing = _mapper.Map<Tasks>(model);


            // save user
            _context.Tasks.Add(Task);
            _context.SaveChanges();
        }

I adjusted the post logic and stuff was unsuccessful, that's about as far as I got.


Solution

  • Per Yong Shun I did not have my rule defined.