'Adding Iservicefactory scope automapper not working

I was using Automapper to mapped the Dto and entity. Earlier automapper was working but when I added code to created the Iservicefactory scope in one of the function, then automapper is throwing an exception. Can someone please help with that.

using var scope = _serviceScopeFactory.CreateScope();
var dbContect = scope.ServiceProvider.GetRequiredService<DbContext>();
Getmapping(lstMessage)


List<MessageEntity> Getmapping(MessageDto lstMesage)
{
    return  Mapper.map(lstMesage, lstMessageEntity);
}
    
    public class MessageDto ()
{
public string TypeId{get;set;}
public string Name{get;set;}
}

public class MessageEntity ()
{
  public int TypeId{get;set;}
  public string Name{get;set;}
}

Before adding scope, GetMapping() method was working fine. now it is giving and exception 

Mapping types:
MessageDto  -> MessageEntity

Type Map configuration:
MessageDto  -> MessageEntity

Destination Member:
TypeId

I am adding an DI for automapper using CreateMap<MessageDto,MessageEntity>() and same is being added into DI. I have also added string to int conversion during mapping.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source