Open Closed

Error mapping types: Volo.Abp.IdentityServer.ApiResources -> IdentityServer4.Models.ApiResource #1316


User avatar
0
dev03 created
  • ABP Framework version: v4.0.2
  • UI type: Angular
  • DB provider: MongoDB
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
2021-05-13 10:20:36.630 +08:00 [ERR] An unhandled exception has occurred while executing the request.
AutoMapper.AutoMapperMappingException: Error mapping types.

Mapping types:
Object -> List`1
System.Object -> System.Collections.Generic.List`1[[IdentityServer4.Models.ApiResource, IdentityServer4.Storage, Version=4.1.1.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b]]
 ---> AutoMapper.AutoMapperMappingException: Error mapping types.

Mapping types:
ApiResource -> ApiResource
Volo.Abp.IdentityServer.ApiResources.ApiResource -> IdentityServer4.Models.ApiResource

Type Map configuration:
ApiResource -> ApiResource
Volo.Abp.IdentityServer.ApiResources.ApiResource -> IdentityServer4.Models.ApiResource

Destination Member:
Properties

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


Mapping types:
ApiResourceProperty -> KeyValuePair`2
Volo.Abp.IdentityServer.ApiResources.ApiResourceProperty -> System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
   at lambda_method864(Closure , ApiResourceProperty , KeyValuePair`2 , ResolutionContext )
   at lambda_method863(Closure , Object , List`1 , ResolutionContext )
   --- End of inner exception stack trace ---
   at lambda_method863(Closure , Object , List`1 , ResolutionContext )
   --- End of inner exception stack trace ---
   at lambda_method863(Closure , Object , List`1 , ResolutionContext )
   at Volo.Abp.AutoMapper.AutoMapperAutoObjectMappingProvider.Map[TSource,TDestination](Object source)
   at Volo.Abp.ObjectMapping.DefaultObjectMapper.AutoMap[TSource,TDestination](Object source)
   at Volo.Abp.ObjectMapping.DefaultObjectMapper.Map[TSource,TDestination](TSource source)
   at Volo.Abp.IdentityServer.ResourceStore.GetAllResourcesAsync()
   at IdentityServer4.Stores.IResourceStoreExtensions.GetAllEnabledResourcesAsync(IResourceStore store)
   at IdentityServer4.ResponseHandling.DiscoveryResponseGenerator.CreateDiscoveryDocumentAsync(String baseUrl, String issuerUri)
   at IdentityServer4.Endpoints.DiscoveryEndpoint.ProcessAsync(HttpContext context)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService)
   at IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
   at Volo.Abp.AspNetCore.MultiTenancy.MultiTenancyMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
  • Steps to reproduce the issue:
  • 1, add a api resource with any property then save
  • 2, open the ids4 well-known page, it will shows the 500 error
  • 3, check identity server logs, it shows above exception message and stack trace

I found the type of the "Properties" property of class "Volo.Abp.IdentityServer.ApiResources.ApiResource" is "List<ApiResourceProperty>", but the type of the "Properties" property of class "IdentityServer4.Models.ApiResource" is "IDictionary<string, string>", is this a bug or i forgot some configs about some abp modules?


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try the same steps with a new project that create by CLI?

    abp new BookStore -t app-pro -u angular -d mongodb
    
  • User Avatar
    0
    dev03 created

    hi

    Can you try the same steps with a new project that create by CLI?

    abp new BookStore -t app-pro -u angular -d mongodb 
    

    Ok, I will try later, and then let you know what happened.

  • User Avatar
    0
    dev03 created

    Should I use the option '--tiered', just like the project I am working on?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Sure.You can use this option.

  • User Avatar
    0
    dev03 created

    I created two project respectively with two versions of abp(4.0.2 & 4.3.0) and tried it, There is no error when using version 4.3.0, but the same error occurs when using version 4.0.2, please see below:

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Add this code will resolve your problem.

    CreateMap<ApiResourceProperty, KeyValuePair<string, string>>()
                    .ReverseMap();
    
    
  • User Avatar
    0
    dev03 created

    Yes, It worked fine, Thanks.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07