Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Mapping IFormFile to IFormFile fails

Open kirollos-hany opened this issue 3 years ago • 0 comments

I'm using mapster in an asp.net core web api project where im mapping an object that has an IFormFile to another object that has another IFormFile, when mapping the Adapt method throws the exception below: System.TypeInitializationException: The type initializer for 'Mapster.TypeAdapter2' threw an exception. ---> Mapster.CompileException: Error while compiling source=Microsoft.AspNetCore.Http.IHeaderDictionary destination=Microsoft.AspNetCore.Http.IHeaderDictionary type=Map ---> System.ArgumentException: Expression of type 'System.Collections.Generic.Dictionary2[System.String,Microsoft.Extensions.Primitives.StringValues]' cannot be used for assignment to type 'Microsoft.AspNetCore.Http.IHeaderDictionary' at System.Linq.Expressions.Expression.Assign(Expression left, Expression right) at Mapster.Adapters.BaseAdapter.CreateBlockExpressionBody(Expression source, Expression destination, CompileArgument arg) at Mapster.Adapters.BaseAdapter.CreateExpressionBody(Expression source, Expression destination, CompileArgument arg) at Mapster.Adapters.BaseAdapter.CreateAdaptFunc(CompileArgument arg) at Mapster.TypeAdapterConfig.CreateMapExpression(CompileArgument arg) --- End of inner exception stack trace --- at Mapster.TypeAdapterConfig.CreateMapExpression(CompileArgument arg) at Mapster.TypeAdapterConfig.CreateMapExpression(TypeTuple tuple, MapType mapType) at Mapster.TypeAdapterConfig.<GetMapFunction>b__58_0(TypeTuple tuple) at Mapster.TypeAdapterConfig.<>c__DisplayClass55_01.<AddToHash>b__0(TypeTuple types) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Mapster.TypeAdapterConfig.GetMapFunction(Type sourceType, Type destinationType) at Mapster.TypeAdapterConfig.GetMapFunction[TSource,TDestination]() at Mapster.TypeAdapter2..cctor() --- End of inner exception stack trace --- at lambda_method1318(Closure , AddRequest ) at AhliFans.WebApi.Area.Admin.Coach.Add.AddEndPoint.HandleAsync(AddRequest request, CancellationToken cancellationToken) in E:\KIRO\AlAhly\src\Api\AhliFans.WebApi\Area\Admin\Coach\Add\AddEndPoint.cs:line 38 at lambda_method1312(Closure , Object ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.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.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at AhliFans.WebApi.Middlewares.ValidationExceptionMiddleware.ValidationExceptionMiddleware.InvokeAsync(HttpContext httpContext) in E:\KIRO\AlAhly\src\Api\AhliFans.WebApi\Middlewares\ValidationExceptionMiddleware\ValidationExceptionMiddleware.cs:line 25 at Ardalis.ListStartupServices.ShowAllServicesMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

kirollos-hany avatar Jul 27 '22 13:07 kirollos-hany

Please use StackOverflow for usage questions, thanks!

andrerav avatar Sep 06 '22 11:09 andrerav