Missing map type configuration or unsupported mapping

Can someone please explain what this error means? I've used automapper onces before but never got this kind of error.

Mistake

The server encountered an error while processing the request. Exception message - Missing type configuration or unsupported mapping. Matching types: Char → QuestionDto System.Char → CollectiveDistributedPolling.QuestionDto Destination path: QuestionDto.Question1.Question1.Question10 [0] Initial value: R '.

Service1.svc.cs

public Service1() {
    Mapper.CreateMap<Question, QuestionDto>();
    Mapper.CreateMap<QuestionDto, Question>();
}

private Question MapToQuestion(QuestionDto q)
{
       return Mapper.Map<QuestionDto, Question>(q);
}

private QuestionDto MapToQuestionDto(Question q) <<< EXCEPTION GETS THROWN HERE
{
       return Mapper.Map<Question, QuestionDto>(q);
}

public QuestionDto ThrowQuestion(string user)
{
       return MapToQuestionDto(Database.GetInstance().ThrowQuestion(user));
}

      

IService1.cs

 [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
        QuestionDto ThrowQuestion(String user);

[DataContract]
    public class QuestionDto
    {
        [DataMember]
        public int ID { get; set; }
        [DataMember]
        public int next { get; set; }   
        [DataMember]
        public String question { get; set; }   
        [DataMember]
        public ICollection<QuestionDto> QuestionPhrase { get; set; } 
        [DataMember]
        public QuestionDto Next{ get; set; } 
        [DataMember]
        public ICollection<QuestionAnswerDto> QuestionAnswer { get; set; } 
        [DataMember]
        public ICollection<UserAnswerDto> UserAnswer { get; set; } 
    }

      

Question.cs

    public partial class Question
    {
        public Question()
        {
            this.QuestionPhrase = new HashSet<Question>();
            this.QuestionAnswer = new HashSet<QuestionAnswer>();
            this.UserAnswer = new HashSet<UserAnswer>();
        }

        public int ID { get; set; }
        public string question { get; set; }
        public Nullable<int> next { get; set; }

        public virtual ICollection<Question> QuestionPhrase { get; set; }
        public virtual Question Next { get; set; }
        public virtual ICollection<QuestionAnswer> QuestionAnswer { get; set; }
        public virtual ICollection<UserAnswer> UserAnswer { get; set; }
    }
}

      

Thanks to danludwig, I could identify the problem. It has something to do with

[DataMember]
public QuestionDto Next{ get; set; } 

      

But this display seems fine to me.

0


source to share


1 answer


This basically means that AutoMapper is missing information on how to map one property to another.

Although I can't tell by looking at the error, you can try the following process to find out which property is missing. Start by ignoring all properties of your assignment type:

Mapper.CreateMap<Question, QuestionDto>()
    .ForMember(d => d.ID, o => o.Ignore())
    .ForMember(d => d.next, o => o.Ignore())
    .ForMember(d => d.question, o => o.Ignore())
    .ForMember(d => d.QuestionPhrase, o => o.Ignore())
    .ForMember(d => d.Next, o => o.Ignore())
    .ForMember(d => d.QuestionAnswer, o => o.Ignore())
    .ForMember(d => d.UserAnswer, o => o.Ignore())
    // also ignore any other properties
;

      

Then, one by one, uncomment the ForMember lines until your exception is raised again. This property AM cannot figure out how to render. I suspect this is one of your collection properties ...



Update

I am wondering if the recursion problem is possible here. Try the following:

.ForMember(d => d.Next, o => o.ResolveUsing(s => {
    var tryToMap = Mapper.Map<QuestionDto>(s.Next); // exception here???
    return null;
}));

      

Not saying you have a data problem here, but if you did, you should expect AM to throw. If yours question.Next == question

, my guess is that AM will overflow the stack trying to display the property of that owner over and over again.

+4


source







All Articles