0

I have a mvc project with a wcf and I am trying to automapper 5.2 passing from DTO to ViewModel of views and gives me the following error.

AutoMapperConfiguration.cs

 public class AutoMapperConfiguration
    {
        public static void Configure()
        {
            Mapper.Initialize(x =>
            {
                #region VM a Dto
                x.CreateMap<UserProfileVM, UserProfile>().ReverseMap();
                x.CreateMap<PaginaVM, PaginaDto>().ReverseMap();
                #endregion
                #region Dto a VM
                x.CreateMap<UserProfile, UserProfileVM>().ReverseMap();
                x.CreateMap<PaginaDto, PaginaVM>().ReverseMap();
                #endregion
            });
        }
    }

Global.asax

protected void Application_Start()
        {
            // configurar la Base de Datos
            System.Data.Entity.Database.SetInitializer(new WebCodeSampleData());

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // configurar el AutoFac
            Bootstrapper.Run();
            // configurar AutoMapper
            AutoMapperConfiguration.Configure();

        }

homecontroller.cs

PaginaDto dto = _paginaService.GetByUrlCache(url);     
meta = Mapper.Map<PaginaDto, PaginaVM>(dto);

PaginaDto.cs and MaginaVM.cs

public class PaginaDto
    {
        public int PaginaId { get; set; }
        public string Url { get; set; }
        public string Controller { get; set; }
        public string Accion { get; set; }
        public string Author { get; set; }
        public string Title { get; set; }
        public string Keywords { get; set; }
        public string Description { get; set; }
    }

Error

Missing type map configuration or unsupported mapping.

Mapping types:
PaginaDto -> PaginaVM
WebBase.Model.Dto.Models.PaginaDto -> WebBase.Web.Models.Shared.PaginaVM

Which can happen since I have it mounted on the WCF Service with DTO to Entity and it works correctly

ascariz
  • 13
  • 1
  • 4
  • Can you try calling your AutoMapperConfiguration.Configure() method before Bootstrapper.Run() method. Bootstrapper.Run will render your views and the corresponding viewmodel will be realized as well, which I am guessing, needs the mapping available. – Jinish Mar 20 '17 at 09:23
  • I have tried it and the same thing happens. I think the problem is that the same is called the class in the Web project and the Application Service project. – ascariz Mar 21 '17 at 16:41
  • Could you show me your AutoMapperConfiguration.cs class definition, in particular the Configure method where you are defining your mappings or profiles (if you are using profiles) – Jinish Mar 22 '17 at 09:00
  • I do not know what you mean. I've changed the class name, and the same error still occurs. My project is this way. ProjectWeb - AutomapperWeb.cs - PaginaVM ProjectService - Automapper.cs - PaginaDto - PaginaService ProjectData - Pagina.cs - PaginaRepository The automapper works in the ProjectService Entity -> Dto and Dto -> Entity [link]http://codepad.org/vpF1lToN [/link] – ascariz Mar 22 '17 at 10:10
  • Well the error that you are getting is that AutoMapper is not able to find the mappings for your entity classes. Now you are calling the method Configure on your AutoMapperConfiguration class. So in this class you must have defined the mappings using CreateMap method or added Mapping profiles. I want to have a look at your mappings to be able to help – Jinish Mar 22 '17 at 11:10
  • Just saw the class definition. Sorry Somehow I wasnt able to see the AutoMapperConfiguration definition till now in the post. Strange. Anyways, in the configuration the following lines are redundant: x.CreateMap().ReverseMap(); x.CreateMap().ReverseMap();. You have already defined mappings above with reverse map. – Jinish Mar 22 '17 at 11:49

0 Answers0