title: No parameterless constructor defined for this object in automapper
body: <h3>Question</h3>
  <p>I have the following value resolver:</p>
  <pre><code>public class StudentResolver : IValueResolver&lt;Lesson, LessonResponse, UserResponse&gt;
  {
      private readonly ApplicationDbContext _dbContext;
  
      public StudentResolver(ApplicationDbContext dbContext)
      {
          _dbContext = dbContext;
      }
      
      public UserResponse Resolve(
          Lesson lesson, 
          LessonResponse response, 
          UserResponse member, 
          ResolutionContext context)
      {
          var user = _dbContext.Users
              .Where(x =&gt; x.Id == lesson.StudentId)
              .FirstOrDefault();
          if (user == null)
              return null;
          var result = Mapper.Map&lt;UserResponse&gt;(user); // this line triggers a &quot;no parameterless constructor&quot;, why?
          return result;
      }
  }
  </code></pre>
  <p>This resolver tries to fetch the <code>Student</code> attribute for this model:</p>
  <pre><code>public class LessonResponse
  {
      public string Id { get; set; }
  
      public UserResponse Student { get; set; }
  }
  </code></pre>
  <p>But on the line:</p>
  <pre><code>var result = Mapper.Map&lt;UserResponse&gt;(user);
  </code></pre>
  <p>I get:</p>
  <blockquote>
  <p>{System.MissingMethodException: No parameterless constructor defined for this object.   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor)   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)   at System.Activator.CreateInstance(Type type, Boolean nonPublic)   at System.Activator.CreateInstance(Type type)   at AutoMapper.MappingOperationOptions`2.CreateInstanceT}</p>
  </blockquote>
  <p>The only type in that expression that should be created is <code>UserResponse</code> which is defined as follows:</p>
  <pre><code>public class UserResponse
  {
      public string Id { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string FullName { get; set; }
      public string UserName { get; set; }
      public string Email { get; set; }
      public string PhoneNumber { get; set; }
      public string Picture { get; set; }
      public string X { get; set; }
  
      public bool IsAdmin { get; set; }
      public bool IsClient { get; set; }
      public bool IsInstructor { get; set; }
  }
  </code></pre>
  <p>But it is constructible, so what am I doing wrong?</p>
  <hr>
  <h3>Extra</h3>
  <p>The mapping profile is the following:</p>
  <pre><code>public class MappingProfile : Profile 
  {
      public MappingProfile() {
          CreateMap&lt;Lesson, LessonResponse&gt;()                
              .ForMember(
                  dest =&gt; dest.Student,
                  opts =&gt; opts.ResolveUsing&lt;StudentResolver&gt;());
  
      }
  }
  </code></pre>
  <p>And the mapping for the user is:</p>
  <pre><code>public class MappingProfile : Profile 
  {
      public MappingProfile() {
          CreateMap&lt;ApplicationUser, UserResponse&gt;()
              .ForMember(
                  dest =&gt; dest.FullName, 
                  opts =&gt; opts.MapFrom(
                      origin =&gt; origin.FirstName + &quot; &quot; + origin.LastName))
              .ForMember(
                  dest =&gt; dest.IsAdmin,
                  opts =&gt; opts.ResolveUsing&lt;IsAdminResolver&gt;())
              .ForMember(
                  dest =&gt; dest.IsInstructor,
                  opts =&gt; opts.ResolveUsing&lt;IsInstructorResolver&gt;())
              .ForMember(
                  dest =&gt; dest.IsClient,
                  opts =&gt; opts.ResolveUsing&lt;IsClientResolver&gt;());
      }
  }
  </code></pre>
  <p>The boolean resolvers are all similar to:</p>
  <pre><code>public class IsAdminResolver : IValueResolver&lt;ApplicationUser, UserResponse, bool&gt;
  {
      private readonly UserManager&lt;ApplicationUser&gt; _userManager;
  
      public IsAdminResolver(UserManager&lt;ApplicationUser&gt; userManager)
      {
          _userManager = userManager;
      }
      
      public bool Resolve(ApplicationUser user, UserResponse response, bool member, ResolutionContext context)
      {
          return _userManager.IsInRoleAsync(user, &quot;Admin&quot;).Result;
      }
  }
  </code></pre>