Note that there are some explanatory texts on larger screens.

plurals
  1. POAutoMapper.AutoMapperMappingException: Type 'System.String' does not have a default constructor
    text
    copied!<p>A strange error began occurring in our code in the lest week or two. I am trying to identify the root cause of the mapping failure. The most-inner exception itself is puzzling: <code>Type 'System.String' does not have a default constructor</code></p> <p><strong>I don't understand what the exception is telling me. Can you explain what has happened and maybe how I could resolve this bug?</strong></p> <p>The mapper is used within a generic method:</p> <pre><code>public TEntity UpdateWithHistory&lt;TEntity&gt;(TEntity entity, int? entityID, int? interviewID) where TEntity : class { var snapshot = _interviewContext.Find&lt;TEntity&gt;(entityID); // This is call that fails var history = Mapper.Map&lt;TEntity, TEntity&gt;(snapshot); _interviewHistory.Set&lt;TEntity&gt;().Add(history); MarkModified(entity); return Mapper.Map(entity, snapshot); } </code></pre> <p>In the above code, snapshot is NOT null. The full exception:</p> <pre><code>AutoMapper.AutoMapperMappingException: Trying to map Recog.Web.Models.InterviewComment to Recog.Web.Models.InterviewComment. Using mapping configuration for Recog.Web.Models.InterviewComment to Recog.Web.Models.InterviewComment Exception of type 'AutoMapper.AutoMapperMappingException' was thrown. ---&gt; AutoMapper.AutoMapperMappingException: Trying to map System.String to System.String. Using mapping configuration for System.String to System.String Destination property: Comment Exception of type 'AutoMapper.AutoMapperMappingException' was thrown. ---&gt; AutoMapper.AutoMapperMappingException: Trying to map System.String to System.String. Using mapping configuration for System.String to System.String Destination property: Comment Exception of type 'AutoMapper.AutoMapperMappingException' was thrown. ---&gt; System.ArgumentException: Type 'System.String' does not have a default constructor at System.Linq.Expressions.Expression.New(Type type) at AutoMapper.DelegateFactory.CreateCtor(Type type) at AutoMapper.Mappers.ObjectCreator.CreateObject(Type type) at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.CreateObject(ResolutionContext context) at AutoMapper.Mappers.TypeMapObjectMapperRegistry.NewObjectPropertyMapMappingStrategy.GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper) at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper) at AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper) at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) --- End of inner exception stack trace --- at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap) --- End </code></pre> <p>The Comment class that is mentioned:</p> <pre><code>public class InterviewComment { [Key] public int? InterviewCommentID { get; set; } [ForeignKey("Interview")] public int? InterviewID { get; set; } [CodeType(CodeTypeEnum.CommentSection)] public int? CommentSectionCodeID { get; set; } [CodeType(CodeTypeEnum.CommentSource)] public int? CommentSourceCodeID { get; set; } [Display(Name = "Comment")] [StringLength(int.MaxValue)] public string Comment { get; set; } [Include] [Association("Interview_1-*_InterviewComment", "InterviewID", "InterviewID", IsForeignKey = true)] public virtual Interview Interview { get; set; } [ReadOnly(true)] [ForeignKey("ModifiedByUser")] public virtual ApplicationUser ApplicationUser { get; set; } [ReadOnly(true)] public string UserName { get { return ApplicationUser != null ? ApplicationUser.GetDisplayName() : null; } } [ReadOnly(true)] public int CreatedByUser { get; set; } [ReadOnly(true)] public DateTime CreatedDateTime { get; set; } [ReadOnly(true)] public int ModifiedByUser { get; set; } [ReadOnly(true)] public DateTime ModifiedDateTime { get; set; } } </code></pre> <p>I'm still reviewing recent commits to identify the change that is causing this. Any insight into the exception would be greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload