Base solution for your next web application
Open Closed

AutoMapper Mapping Exception #8761


User avatar
0
alfar_re created

Hi,

I'm getting this error on the bold line of code below

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

`public async Task<string> GenerateNumberAsync(ModuleProfile profile, int tenantId)
        {
            var numberFormat = await _numberFormatRepository.GetAll().Where(e => e.Module == profile && e.TenantId == tenantId).FirstOrDefaultAsync();

            long _current = numberFormat.Current;
            int _seed = numberFormat.Seed;
            long _new = _current + _seed;
            long? _total = 1 + numberFormat.Total;
            string _number = string.Concat(numberFormat.Prefix.Trim(), _new.ToString(), numberFormat.Postfix.Trim());
            //
            var newNumberFormat = new NumberFormats.Dtos.GetNumberFormatForViewDto()
            {
         `       NumberFormat = new NumberFormats.Dtos.NumberFormatDto
                {
                    Current = _new,
                    Total = _total,
                }
            };
######             **ObjectMapper.Map(newNumberFormat, numberFormat);**
            //
            return _number;
        }

4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    What is the full stack error message?

  • User Avatar
    0
    alfar_re created

    Hi,

    Here you go.

    AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
    
    Mapping types:
    GetNumberFormatForViewDto -> NumberFormat
    reos.NumberFormats.Dtos.GetNumberFormatForViewDto -> reos.NumberFormats.NumberFormat
       at lambda_method(Closure , GetNumberFormatForViewDto , NumberFormat , ResolutionContext )
       at Abp.AutoMapper.AutoMapperObjectMapper.Map[TSource,TDestination](TSource source, TDestination destination)
       at reos.Leases.LeasesAppService.GenerateNumberAsync(ModuleProfile input, Int32 tenantId) in D:\OneDrive\Projects\reos\src\reos.Application\Leases\LeasesAppService.cs:line 351
       at reos.Leases.LeasesAppService.Create(CreateOrEditLeaseDto input) in D:\OneDrive\Projects\reos\src\reos.Application\Leases\LeasesAppService.cs:line 162
       at Abp.Threading.InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(Task actualReturnValue, Func`1 postAction, Action`1 finalAction)
       at reos.Leases.LeasesAppService.CreateOrEdit(CreateOrEditLeaseDto input) in D:\OneDrive\Projects\reos\src\reos.Application\Leases\LeasesAppService.cs:line 144
       at lambda_method(Closure , Object )
       at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
       at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Did you add mapping to CustomDtoMapper.cs for GetNumberFormatForViewDto to NumberFormat ?

  • User Avatar
    0
    alfar_re created

    Hi,

    I added the mapping and it worked. I guess that was the step I was missing. Thanks a gigabyte @ismcagdas.