Base solution for your next web application
Open Closed

AutoMapper.AutoMapperMappingException: Error mapping types. #11717


User avatar
0
alliance225 created

Hi, I have these entities: namespace DocuPro.DocumentBase { [Table("DocumentVersions")] [Audited] public class DocumentVersion : Entity, IMayHaveTenant { public int? TenantId { get; set; }

    public virtual int? DocumentId { get; set; }

    [ForeignKey("DocumentId")]
    public Document DocumentFk { get; set; }
    public virtual ICollection<DocumentVersionFile> DocumentVersionFiles { get; set; }


}

} namespace DocuPro.DocumentBase { [Table("DocumentVersionFiles")] [Audited] public class DocumentVersionFile : Entity, IMayHaveTenant { public int? TenantId { get; set; }

    public virtual string OCR { get; set; }

    public virtual string FileName { get; set; }
    
    
    public virtual int? DocumentVersionId { get; set; }

    [ForeignKey("DocumentVersionId")]
    public DocumentVersion DocumentVersionFk { get; set; }
    

    
    public virtual int? FileTypeId { get; set; }

    [ForeignKey("FileTypeId")]
    public FileType FileTypeFk { get; set; }

}

} namespace DocuPro.DocumentBase { [Table("FileTypes")] public class FileType : Entity {

    [Required]
    public virtual string Extension { get; set; }

}

}

I have this DTO: namespace DocuPro.DocumentBase.Dtos { public class GetDocumentVersionForViewDto { public DocumentVersionDto DocumentVersion { get; set; }

    public string DocumentLibelle { get; set; }

}

}

In my service I have this method:

public virtual async Task<List<GetDocumentVersionForViewDto>> GetAllDocumentVersion(int documentId) { // Fetching all DocumentVersions (and associated DocumentVersionFiles) for a specific documentId var documentVersions = await _documentVersionRepository.GetAllIncluding(dv => dv.DocumentVersionFiles) .Where(dv => dv.DocumentId == documentId) .ToListAsync();

  // Mapping to DTO
  var documentVersionDtos = ObjectMapper.Map&lt;List&lt;GetDocumentVersionForViewDto&gt;>(documentVersions);

  return documentVersionDtos;

}

I get this error: XHRGET https://localhost:44302/App/DocumentTabs/TabViewInfomations?documentId=8 [HTTP/2 500 Internal Server Error 250ms]

AutoMapper.AutoMapperMappingException: Error mapping types.

Mapping types:

List1 -> List1

System.Collections.Generic.List1[[DocuPro.DocumentBase.DocumentVersion, DocuPro.Core, Version=12.3.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.List1[[DocuPro.DocumentBase.Dtos.GetDocumentVersionForViewDto, DocuPro.Application.Shared, Version=12.3.0.0, Culture=neutral, PublicKeyToken=null]]

---> AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types: DocumentVersion -> GetDocumentVersionForViewDto DocuPro.DocumentBase.DocumentVersion -> DocuPro.DocumentBase.Dtos.GetDocumentVersionForViewDto at lambda_method3201(Closure, DocumentVersion, GetDocumentVersionForViewDto, ResolutionContext) at lambda_method3200(Closure, Object, List`1, ResolutionContext)

--- End of inner exception stack trace --- at lambda_method3200(Closure, Object, List1, ResolutionContext) at Abp.AutoMapper.AutoMapperObjectMapper.Map[TDestination](Object source) at DocuPro.DocumentBase.DocumentVersionsAppService.GetAllDocumentVersion(Int32 documentId) in C:\Users\hp\OneDrive\APPS\DocuProV10\src\DocuPro.Application\DocumentBase\DocumentVersionsAppService.cs:line 43 at Abp.Authorization.AuthorizationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at DocuPro.Web.Areas.App.Controllers.Documents.DocumentTabsController.TabViewInfomations(Nullable1 state, Int32 documentId) in C:\Users\hp\OneDrive\APPS\DocuProV10\src\DocuPro.Web.Mvc\Areas\App\Controllers\Documents\DocumentTabsController.cs:line 84 at lambda_method3030(Closure, Object)


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alliance225

    Did you add mappings to CustomDtoMapper.cs under Application project ?