title: Mapper not initialized, When Use ProjectTo()
body: <p>I Use <strong>Automapper 5.2.0</strong> In My Project. When I Use <code>ProjectTo()</code> In Code Get This Error:</p>
  
  <blockquote>
    <p>Mapper not initialized. Call Initialize with Appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.</p>
  </blockquote>
  
  <p><strong>Service Code</strong></p>
  
  <pre><code> public async Task&lt;FreelancerProfileViewModel&gt; GetFreelancerProfile()
      {
          var id = Guid.Parse(_identity.GetUserId());
          var model = await _freelancerProfiles
              .AsNoTracking()
              .Where(_ =&gt; _.User.Id == id)
              .ProjectTo&lt;FreelancerProfileViewModel&gt;()
              .FirstAsync();
  
       //  var viewmodel =  _mapper.Map&lt;FreelancerProfileViewModel&gt;(model);
  
          return model;
      }
  </code></pre>
  
  <p><strong>Automapper Profile</strong></p>
  
  <pre><code>   public class FreelancerDashbordProfile : Profile
  {
      private readonly IIdentity _identity;
      public FreelancerDashbordProfile(IIdentity identity)
      {
          _identity = identity;
          var id = Guid.Parse(_identity.GetUserId());
          CreateMap&lt;FreelancerProfile, FreelancerProfileViewModel&gt;()
          .ForMember(_ =&gt; _.DoingProjectCount,
              __ =&gt; __.MapFrom(_ =&gt; _.Projects.Count(project =&gt; project.ProjectState == ProjectState.Doing)))
  
          .ForMember(_ =&gt; _.EndProjectCount,
              __ =&gt; __.MapFrom(_ =&gt; _.Projects.Count(project =&gt; project.ProjectState == ProjectState.End)))
  
          .ForMember(_ =&gt; _.ProjectCount, __ =&gt; __.MapFrom(_ =&gt; _.Projects.Count));
  
      }
  
  }
  </code></pre>
  
  <p>Also I Use <a href="http://structuremap.github.io/quickstart/" rel="noreferrer">StructureMap</a> For <a href="https://en.wikipedia.org/wiki/Inversion_of_control" rel="noreferrer">IoC</a> </p>
  
  <p><strong>AutoMapperRegistery</strong></p>
  
  <pre><code>   public AutoMapperRegistery()
      {
  
          this.Scan(scan =&gt;
          {
              scan.TheCallingAssembly();
              scan.AssemblyContainingType&lt;SkillProfile&gt;(); // for other asms, if any.
              scan.WithDefaultConventions();
  
              scan.AddAllTypesOf&lt;Profile&gt;().NameBy(item =&gt; item.FullName);
          });
  
          this.For&lt;MapperConfiguration&gt;().Singleton().Use("MapperConfig", ctx =&gt;
          {
              var config = new MapperConfiguration(cfg =&gt;
              {
                  cfg.CreateMissingTypeMaps = true; // It will connect `Person` &amp; `PersonViewModel` automatically.
                  addAllCustomAutoMapperProfiles(ctx, cfg);
              });
              config.AssertConfigurationIsValid();
  
              return config;
          });
  
          this.For&lt;IMapper&gt;()
              .Singleton()
              .Use(ctx =&gt; ctx.GetInstance&lt;MapperConfiguration&gt;().CreateMapper(ctx.GetInstance));
  
  
      }
  </code></pre>
  
  <p>I See Other <a href="https://stackoverflow.com/questions/39417633/automapper-with-entity-framework-initialization-error">Question</a> and <a href="https://github.com/AutoMapper/AutoMapper/issues/1524" rel="noreferrer">Issue</a> but not solved my problem.</p>