Automapper performance issue only when debugging in Visual Studio
<p>In my WPF application I am using AutoMapper to map from the entities to the domain objects. </p>

<p>For one particular mapping I am seeing a substantial slow down when running the application with debugging (F5) versus without (CTRL + F5). 
Without debugging this mapping takes &lt; 1 second, but with debugging it takes ~14 seconds.</p>

<p>The domain objects (simplified for brevity):</p>

<pre><code>public class CompanyModel : UpdateableModel
{
    public CompanyModel() : this(true){}

    public CompanyModel(bool isNewModel) : base(isNewModel)
    {
        Projects = new ObservableCollectionEx&lt;ProjectModel&gt;();
        Projects.ItemPropertyChanged += (sender, args) =&gt; OnPropertyChanged("Projects");
    }

    public int? Id { get; set;}
    public string Name { get; set; }
    public string CompanyXref { get; set; }
    public bool IsActive { get; set; }
    public ObservableCollectionEx&lt;ProjectModel&gt; Projects { get; set;}
    public DateTime? DateUpdated { get; set;}
}

public class ProjectModel : UpdateableModel
{
    public ProjectModel() : this(true){}

    public ProjectModel(bool isNewModel) : base(isNewModel)
    {
        Tasks = new ObservableCollectionEx&lt;ProjectTaskModel&gt;();

        SetPropertyDefault(() =&gt; StartDate, DateTime.Today);
        SetPropertyDefault(() =&gt; EndDate, DateTime.Today);

        // ReSharper disable once ExplicitCallerInfoArgument
        Tasks.ItemPropertyChanged += (sender, args) =&gt; OnPropertyChanged("Tasks");
    }

    public int? Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public string BillingCurrency { get; set; }
    public string ExternalXref { get; set; }
    public bool IsChargeable { get; set; }        
    public bool IsActive { get; set; }
    public int TimeTypeId { get; set; }
    public ObservableCollectionEx&lt;ProjectTaskModel&gt; Tasks { get; set;}
    public DateTime? DateUpdated { get; set; }
}

public class ProjectTaskModel : UpdateableModel
{
    public ProjectTaskModel() : this(true){}

    public ProjectTaskModel(bool isNewModel) : base(isNewModel)
    {
        SetPropertyDefault(() =&gt; StartDate, DateTime.Today);
        SetPropertyDefault(() =&gt; EndDate, DateTime.Today);
    }

    public int? Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public DateTime StartDate { get; set; }        
    public DateTime EndDate { get; set; }
    public string ExternalXref { get; set; }
    public bool IsActive { get; set; }
    public DateTime? DateUpdated { get; set; }
}
</code></pre>

<p>The entities:</p>

<pre><code>public class CompanyEntity : BaseEntity
{
    public virtual string CompanyName { get; set; }
    public virtual string CompanyXref { get; set; }
    public virtual bool IsActive { get; set; }
    public virtual IList&lt;ProjectEntity&gt; Projects { get; set; }

    public virtual DateTime? DateUpdated { get; set; }
}

public class ProjectEntity : BaseEntity
{
    public virtual string ProjectName { get; set; }
    public virtual string Description { get; set; }
    public virtual DateTime StartDate { get; set; }
    public virtual DateTime EndDate { get; set; }
    public virtual string ExternalXref { get; set; }
    public virtual bool IsChargeable { get; set; }
    public virtual bool IsActive { get; set; }

    public virtual int TimeTypeId { get; set; }
    public virtual string CurrencyId { get; set; }

    public virtual CompanyEntity ClientCompany { get; set; }
    public virtual DateTime? DateUpdated { get; set; }

    public virtual IList&lt;ProjectTaskEntity&gt; Tasks { get; set; }
}

public class ProjectTaskEntity : BaseEntity
{
    public virtual string ProjectTaskName { get; set; }
    public virtual string Description { get; set; }
    public virtual DateTime StartDate { get; set; }
    public virtual DateTime EndDate { get; set; }
    public virtual string ExternalXref { get; set; }
    public virtual bool IsActive { get; set; }

    public virtual DateTime? DateUpdated { get; set; }

    public virtual ProjectEntity Project { get; set; }
}
</code></pre>

<p>Finally the mappings, all properties are currently explicitly mapped:</p>

<pre><code>CreateMap&lt;CompanyEntity, CompanyModel&gt;()
    .ConstructUsing((CompanyEntity src) =&gt; new CompanyModel(false))
    .MapMember(dest =&gt; dest.Id, src =&gt; src.Id)
    .MapMember(dest =&gt; dest.Name, src =&gt; src.CompanyName)
    .MapMember(dest =&gt; dest.CompanyXref, src =&gt; src.CompanyXref)
    .MapMember(dest =&gt; dest.IsActive, src =&gt; src.IsActive)
    .MapMember(dest =&gt; dest.Projects, src =&gt; src.Projects)
    .IgnoreMember(dest =&gt; dest.State);

CreateMap&lt;ProjectEntity, ProjectModel&gt;()
    .ConstructUsing((ProjectEntity src) =&gt; new ProjectModel(false))
    .MapMember(dest =&gt; dest.Id, src =&gt; src.Id)
    .MapMember(dest =&gt; dest.Name, src =&gt; src.ProjectName)
    .MapMember(dest =&gt; dest.Description, src =&gt; src.Description)
    .MapMember(dest =&gt; dest.BillingCurrency, src =&gt; src.CurrencyId)
    .MapMember(dest =&gt; dest.StartDate, src =&gt; src.StartDate)
    .MapMember(dest =&gt; dest.EndDate, src =&gt; src.EndDate)
    .MapMember(dest =&gt; dest.ExternalXref, src =&gt; src.ExternalXref)
    .MapMember(dest =&gt; dest.IsActive, src =&gt; src.IsActive)
    .MapMember(dest =&gt; dest.IsChargeable, src =&gt; src.IsChargeable)
    .MapMember(dest =&gt; dest.Tasks, src =&gt; src.Tasks)
    .MapMember(dest =&gt; dest.TimeTypeId, src =&gt; src.TimeTypeId)
    .IgnoreMember(dest =&gt; dest.State);

CreateMap&lt;ProjectTaskEntity, ProjectTaskModel&gt;()
    .ConstructUsing((ProjectTaskEntity src) =&gt; new ProjectTaskModel(false))
    .MapMember(dest =&gt; dest.Id, src =&gt; src.Id)
    .MapMember(dest =&gt; dest.Name, src =&gt; src.ProjectTaskName)
    .MapMember(dest =&gt; dest.Description, src =&gt; src.Description)
    .MapMember(dest =&gt; dest.StartDate, src =&gt; src.StartDate)
    .MapMember(dest =&gt; dest.EndDate, src =&gt; src.EndDate)
    .MapMember(dest =&gt; dest.ExternalXref, src =&gt; src.ExternalXref)
    .MapMember(dest =&gt; dest.IsActive, src =&gt; src.IsActive)
    .IgnoreMember(dest =&gt; dest.State);
</code></pre>

<p>When the mapping is performed there are 16 companies, 122 total projects, and each project only has one task currently.</p>

<p>I did try ignoring various properties on the mappings and it seems to be the Tasks collection at the project level that is causing this; with it ignored the mapping takes 2 seconds instead of 14.</p>

<p>Is there something about how Visual Studio hosts the application for debugging that could cause this performance issue?</p>