Open Closed

Issue with overloading App Service method #7285


0
rsmith created

Hi,

I am getting a 500 error when I attempt to call a Service method that is overloaded.

The interesting observation in the error is the parameters are being replaced by MyApp.Intranet.Application, which is possibly making them identical calls.

Does the AppService support overloads and how should we implement? Thanks

Code:

    Task<PagedResultDto<UserProfileListDto>> GetUsersWithProfiles();

    Task<PagedResultDto<UserProfileListDto>> GetUsersWithProfiles(GetUserProfileListInput input);

When hitting the service url in the browser I expect json data returned but receive the following error. http://localhost:45777/api/services/app/User/GetUsersWithProfiles

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

VanEck.Intranet.Authorization.Users.UserAppService.GetUsersWithProfiles (MyApp.Intranet.Application) VanEck.Intranet.Authorization.Users.UserAppService.GetUsersWithProfiles (MyApp.Intranet.Application)




2 Answer(s)
  • 0
    ryancyq created

    Hi, how app service works is by converting the app service class into a asp net core controller, it uses action name (e.g Get/GetAll) for routing.

    However, aspnet core does not support multiple actions with the same routing and differ only by parameters. See https://github.com/aspnet/Mvc/issues/6898

    you can consider using different action names or handle both use cases in the same action (GetUsersWithProfiles)

  • 0
    maliming created

    This is a limitation of MVC.

    You should merge them into a single method, the arguments can be null, or use different method names. Or define different routes, using ActionName.

    Task<PagedResultDto<UserProfileListDto>> GetUsersWithProfiles();
    Task<PagedResultDto<UserProfileListDto>> GetUsersWithProfiles(GetUserProfileListInput input);