I’m not sure if I have a threading issue here or not. On the page load I am executing two Ajax requests to load some additional data from a third party API. Here is what each method looks like that gets called:
private List<CaseCommentModel> GetCaseCommentModels(string caseId) {
var comments = CaseService.GetAllCaseCommentsByCaseId(caseId);
Mapper.Reset();
Mapper.CreateMap<CrmCaseComment, CaseCommentModel>();
var caseCommentModels = Mapper.Map<List<CrmCaseComment>, List<CaseCommentModel>>(comments);
return caseCommentModels;
}
private List<CaseAttachmentModel> GetCaseAttachmentModels(string caseId) {
var attachments = AttachmentService.GetAttachmentsByParentId(caseId);
Mapper.Reset();
Mapper.CreateMap<CrmAttachment, CaseAttachmentModel>();
var caseAttachmentModels = Mapper.Map<List<CrmAttachment>, List<CaseAttachmentModel>>(attachments);
return caseAttachmentModels;
}
Sometimes both responses succeed. But, if I refresh the page, sometimes one will fail with the following exception:
Missing type map configuration or unsupported mapping
I can go from both requests succeeding to one failing without making any code changes; all it takes is a refresh of the page. Is this a threading issue or am I using the mapper incorrectly?
You should Create a Mapping only once per application life time. So, move each specific
CreateMapto app start.The problem you are experiencing is probably related to the race to do the mapping before the other thread calls
Mapper.Reset()