Search code examples
asp.net-mvcdependency-injectionabp-framework

Remote service 'Default' was not found and there is no default configuration error with abp MVC project


I created a new solution by using below CLI command

abp new Acme.BookStore -dbms MySQL -csf 

I am trying to follow the same steps in this tutorial

https://docs.abp.io/en/abp/latest/Tutorials/Part-3?UI=MVC&DB=EF

After I completed the steps to create model to insert the entity. When I run the page and click "Add new" button I got below error.

2023-07-15 22:53:00.914 +03:00 [ERR] ---------- RemoteServiceErrorInfo ----------
{
  "code": null,
  "message": "Sayfa işlenirken sunucu tarafında beklenmedik bir hata oluştu!",
  "details": null,
  "data": {
    "ActivatorChain": "FMS.Web.Pages.Participant.CreateModalModel"
  },
  "validationErrors": null
}

2023-07-15 22:53:00.914 +03:00 [ERR] An exception was thrown while activating FMS.Web.Pages.Participant.CreateModalModel.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating FMS.Web.Pages.Participant.CreateModalModel.
 ---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'FMS.Web.Pages.Participant.CreateModalModel' can be invoked with the available services and parameters:
Cannot resolve parameter 'FMS.ServiceInterface.IParticipantAppService participantAppService' of constructor 'Void .ctor(FMS.ServiceInterface.IParticipantAppService)'.

See https://autofac.rtfd.io/help/no-constructors-bindable for more info.
   at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass14_0.<UseSingleConstructorActivation>b__0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   --- End of inner exception stack trace ---
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
   at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
   at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Volo.Abp.AspNetCore.Mvc.UI.RazorPages.ServiceBasedPageModelActivatorProvider.<>c__DisplayClass0_0.<CreateActivator>b__0(PageContext context)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageModelFactoryProvider.<>c__DisplayClass3_0.<CreateModelFactory>b__0(PageContext pageContext)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.CreateInstance()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2023-07-15 22:53:00.919 +03:00 [ERR] ---------- Exception Data ----------

After some research, I did following changes.

  1. I referenced Application, Application.Contract, Domain, Domain.Shared and FrameworkCore projects to web project.

  2. I added AbpHttpClientModule on dependson attribute in web projects webmodule file.
    [DependsOn(
    typeof(FMSHttpApiModule),
    typeof(FMSApplicationModule),
    typeof(FMSEntityFrameworkCoreModule),
    typeof(AbpAutofacModule),
    typeof(AbpIdentityWebModule),
    typeof(AbpSettingManagementWebModule),
    typeof(AbpAccountWebOpenIddictModule),
    typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule),
    typeof(AbpTenantManagementWebModule),
    typeof(AbpAspNetCoreSerilogModule),
    typeof(AbpSwashbuckleModule),
    typeof(AbpHttpClientModule) //used to create client proxies
    )]
    [DependsOn(typeof(AbpFeatureManagementWebModule))]
    public class FMSWebModule : AbpModule
    {
    ...
    }

  3. In the ConfigureServices function I added below lines

    context.Services.AddHttpClientProxies(
        typeof(FMSApplicationContractsModule).Assembly);
    context.Services.AddHttpClientProxies(
        typeof(FMSApplicationModule).Assembly);
    context.Services.AddHttpClientProxies(
        typeof(FMSDomainSharedModule).Assembly);
    context.Services.AddHttpClientProxies(
        typeof(FMSDomainModule).Assembly);
    

After these changes, first error is resolved and "Add new entity" modal can be opened. After filling in the information in the create modal, when I click save below error is logged.

The logs contain below messages.

2023-07-18 22:27:59.052 +03:00 [INF] Executing endpoint '/Participant/CreateModal'
2023-07-18 22:27:59.052 +03:00 [INF] Route matched with {page = "/Participant/CreateModal", area = "", action = "", controller = ""}. Executing page /Participant/CreateModal
2023-07-18 22:27:59.052 +03:00 [INF] Skipping the execution of current filter as its not the most effective filter implementing the policy Microsoft.AspNetCore.Mvc.ViewFeatures.IAntiforgeryPolicy
2023-07-18 22:27:59.069 +03:00 [INF] Executing handler method FMS.Web.Pages.Participant.CreateModalModel.OnPostAsync - ModelState is "Valid"
2023-07-18 22:28:02.789 +03:00 [ERR] ---------- RemoteServiceErrorInfo ----------
{
  "code": null,
  "message": "Sayfa işlenirken sunucu tarafında beklenmedik bir hata oluştu!",
  "details": null,
  "data": {},
  "validationErrors": null
}

2023-07-18 22:28:02.789 +03:00 [ERR] Remote service 'Default' was not found and there is no default configuration.
Volo.Abp.AbpException: Remote service 'Default' was not found and there is no default configuration.
   at Volo.Abp.Http.Client.RemoteServiceConfigurationDictionary.GetConfigurationOrDefault(String name)
   at Volo.Abp.Http.Client.RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(String name)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.GetActionApiDescriptionModel(IAbpMethodInvocation invocation)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at FMS.Web.Pages.Participant.CreateModalModel.OnPostAsync() in /Users/serhatonal/Documents/Codes/FMS/FMS/src/FMS.Web/Pages/Participant/CreateModal.cshtml.cs:line 27
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.GenericTaskHandlerMethod.Convert[T](Object taskAsObject)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.GenericTaskHandlerMethod.Execute(Object receiver, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
2023-07-18 22:28:02.804 +03:00 [INF] Executing ObjectResult, writing value of type 'Volo.Abp.Http.RemoteServiceErrorResponse'.
2023-07-18 22:28:02.805 +03:00 [INF] Executed page /Participant/CreateModal in 3753.4906ms
2023-07-18 22:28:02.805 +03:00 [INF] Executed endpoint '/Participant/CreateModal'
2023-07-18 22:28:03.002 +03:00 [DBG] Added 0 entity changes to the current audit log
2023-07-18 22:28:03.009 +03:00 [DBG] Added 0 entity changes to the current audit log
2023-07-18 22:28:03.010 +03:00 [INF] Request finished HTTP/1.1 POST https://localhost:44325/Participant/CreateModal application/x-www-form-urlencoded;+charset=UTF-8 603 - 500 - application/json;+charset=utf-8 3971.0105ms

Below is the CreateModal.cshtml

@page
@using FMS.Localization
@using FMS.Web.Pages.Participant
@using Microsoft.Extensions.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@model CreateModalModel
@inject IStringLocalizer<FMSResource> L
@{
    Layout = null;
}
<abp-dynamic-form abp-model="Participant" asp-page="/Participant/CreateModal">
    <abp-modal>
        <abp-modal-header title="@L["NewParticipant"].Value"></abp-modal-header>
        <abp-modal-body>
            <abp-form-content />
        </abp-modal-body>
        <abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
    </abp-modal>
</abp-dynamic-form>

Below is the CreateModel.cshtml.cs

using System.Threading.Tasks;
using FMS.Dtos;
using FMS.ServiceInterface;
using Microsoft.AspNetCore.Mvc;

namespace FMS.Web.Pages.Participant;

public class CreateModalModel : ParticipantPageModel
{
    [BindProperty]
    public ParticipantDto Participant { get; set; }

    private readonly IParticipantAppService _participantAppService;

    public CreateModalModel(IParticipantAppService participantAppService)
    {
        _participantAppService = participantAppService;
    }

    public void OnGet()
    {
        Participant = new ParticipantDto();
    }

    public async Task<IActionResult> OnPostAsync()
    {
        await _participantAppService.CreateAsync(Participant);
        return NoContent();
    }
}

Error is thrown at "await _participantAppService.CreateAsync(Participant);" line.

Below is the implementation of IParticipantAppService

namespace FMS.ServiceInterface;

public interface IParticipantAppService: ICrudAppService<
    ParticipantDto,
    Guid,
    PagedAndSortedResultRequestDto,
    ParticipantDto>
{

}

And implementation of ParticipantService

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FMS.Dtos;
using FMS.Fairs;
using FMS.Managers;
using FMS.Repositories;
using FMS.ServiceInterface;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Users;

namespace FMS.Fairs;

public class ParticipantService: CrudAppService<
    Participant,
    ParticipantDto,
    Guid,
    PagedAndSortedResultRequestDto, ParticipantDto>,
    IParticipantAppService  
{
        private readonly IDataFilter _dataFilter;
        private readonly IParticipantRepository _participantRepository;
        private readonly ICurrentTenant _currentTenant;
        private readonly ICurrentUser _currentUser;
        private readonly IObjectMapper _objectMapper;
        private readonly IGuidGenerator _guidGenerator;
        private readonly FairManager _fairManager;

        public ParticipantService(
        ICurrentTenant currentTenant,
        ICurrentUser currentUser,
        IDataFilter dataFilter,
        IParticipantRepository participantRepository,
        IObjectMapper objectMapper,
            IGuidGenerator guidGenerator,
            FairManager fairManager)
        :base(participantRepository)
    {
        _dataFilter = dataFilter;
        _participantRepository = participantRepository;
        _currentTenant = currentTenant;
        _currentUser = currentUser;
        _objectMapper = objectMapper;
            _guidGenerator = guidGenerator;
            _fairManager = fairManager;
    }


        public override Task<ParticipantDto> CreateAsync(ParticipantDto input)
        {
            return base.CreateAsync(input);
        }
    }

Any help is appreciated.


Solution

  • In the Web project appsettings.json file I added below configuration and it worked.

      "RemoteServices": {
        "Default": {
          "BaseUrl": "https://localhost:44325/"
        }
      }