Threading autoprocessor error (missing card configuration or unsupported display)?

I am not sure if there is a problem with threads here or not. When loading the page, I execute two Ajax requests to load some additional data from a third-party API. Here's what each method called is:

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 answers fail. But, if I refresh the page, sometimes one will fail with the following exception:

Missing type map configuration or unsupported mapping

I can move from both queries to the next without making any code changes; all that is required is a page refresh. Is this a thread problem or am I using cartography incorrectly?

+7
source share
4 answers

You must create a mapping only once for each lifetime of the application. So, move each specific CreateMap to the top of the application.

The problem you are facing is probably related to the race in order to do a match before another thread calls Mapper.Reset()

+5
source

Yes, you have a threading issue and you are using the Automapper configuration incorrectly. On the Automapper page, top of page :

If you use the static Mapper method, the configuration should occur once in the AppDomain. This means the best place for the configuration code is in the application startup, for example, the Global.asax file for ASP.NET applications. Typically, the configuration of the bootstrapper class is in its class, and this bootstrap class is called from the startup method.

Thus, you should not have Mapper.CreateMap inside the controller actions, moving them to the usual place and executing them once.

Or, if you need a dynamic mapping configuration, do not use the static Mapper instead of building the configuration and the engine manually:

 var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers()); config.CreateMap<CrmCaseComment, CaseCommentModel>(); var engine = new MappingEngine(config); var caseCommentModels = engine.Map<List<CrmCaseComment>, List<CaseCommentModel>>(comments); 
+10
source

I ran into a Threading problem and would like to share my findings.

In my application in the WCF Services Designer, I called AutoMapperRegistry. Configure () to create mappings for automatic matching.

From the MVC controller, I call the service by calling the singleton WCF service object .

actual problem is related to the web client . I actually called asyncrounusly two of the controller methods so that both are passed to the service and the result is returned. The moment I changed the first method to Async false, the problem was resolved .

Cause When both methods are called async, a race condition also occurs from time to time that it resolves on its own, sometimes this threading problem is created, resulting in the above exception being thrown.

+1
source

Yes, you have a problem with threads, and the best solution (in my opinion) is to stop using the static API from AutoMapper.

I suggest you configure automapper as follows: // Register IoC (Autofac in my case)

 builder .Register(c => new MapperConfiguration(cfg => { cfg.AddProfile<AutoMapperProfile>(); })) .SingleInstance(); builder .Register(c => c.Resolve<MapperConfiguration>().CreateMapper()) .As<AutoMapper.IMapper>(); 

Note that I am creating the MapperConfiguration as a single instance. The AutoMapperProfile.cs class contains the automapper configuration:

 class AutoMapperProfile : Profile { public AutoMapperProfile() { CreateMap<Source, Destination>(); // usual configurations... } } 
0
source

All Articles