Open Closed

Getting exception when trying to register dynamic proxies from another web application #9270


User avatar
0
sinancondo created

I am trying to create webapplication that consume dynamic proxy , and when I run the app I get this error

System.AggregateException
  HResult=0x80131500
  Message=Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Volo.Abp.Http.ProxyScripting.IProxyScriptManager Lifetime: Transient ImplementationType: Volo.Abp.Http.ProxyScripting.ProxyScriptManager': Unable to resolve service for type 'Volo.Abp.Http.Modeling.IApiDescriptionModelProvider' while attempting to activate 'Volo.Abp.Http.ProxyScripting.ProxyScriptManager'.) (Error while validating the service descriptor 'ServiceType: Volo.Abp.Http.ProxyScripting.ProxyScriptManager Lifetime: Transient ImplementationType: Volo.Abp.Http.ProxyScripting.ProxyScriptManager': Unable to resolve service for type 'Volo.Abp.Http.Modeling.IApiDescriptionModelProvider' while attempting to activate 'Volo.Abp.Http.ProxyScripting.ProxyScriptManager'.)
  Source=Microsoft.Extensions.DependencyInjection
  StackTrace:
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
   at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
   at Program.<<Main>$>d__0.MoveNext() in   TestHarness.Api.Host\Program.cs:line 18

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1:

InvalidOperationException: Error while validating the service descriptor 'ServiceType: Volo.Abp.Http.ProxyScripting.IProxyScriptManager Lifetime: Transient ImplementationType: Volo.Abp.Http.ProxyScripting.ProxyScriptManager': Unable to resolve service for type 'Volo.Abp.Http.Modeling.IApiDescriptionModelProvider' while attempting to activate 'Volo.Abp.Http.ProxyScripting.ProxyScriptManager'.

Inner Exception 2:

InvalidOperationException: Unable to resolve service for type 'Volo.Abp.Http.Modeling.IApiDescriptionModelProvider' while attempting to activate 'Volo.Abp.Http.ProxyScripting.ProxyScriptManager'.

program.cs :

using Cao.CatOs.TestHarness.Api.Host.Modules;
using Volo.Abp;

var builder = WebApplication.CreateBuilder(args);

await builder.AddApplicationAsync<CatOsHttpApiClientTestModule>(options =>
{
    var configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.AddJsonFile("appsettings.json", false);
    configurationBuilder.AddJsonFile("appsettings.secrets.json", true);

     options.Services.ReplaceConfiguration(configurationBuilder.Build());
    options.UseAutofac();
    options.ApplicationName = "test";
});


var application = builder.Build();
await application.InitializeAsync();

Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();

await application.WaitForShutdownAsync();

Module :

  public class CatOsHttpApiClientTestModule : AbpModule
  {
      private readonly string RemoteServiceName = "Default";

      public override void ConfigureServices(ServiceConfigurationContext context)
      {
          context.Services.AddHttpClientProxies(
              typeof(CatOsApplicationContractsModule).Assembly,
              RemoteServiceName
          );

          context.Services.AddAutofac();
          context.Services.AddControllers();
          context.Services.AddEndpointsApiExplorer();
          context.Services.AddHttpContextAccessor();
          context.Services.AddScoped<ScenarioManager>();
          context.Services.AddSwaggerGen(options =>
          {
              options.AddSecurityDefinition(
                  "Bearer",
                  new Microsoft.OpenApi.Models.OpenApiSecurityScheme
                  {
                      Name = "Authorization",
                      Type = Microsoft.OpenApi.Models.SecuritySchemeType.Http,
                      Scheme = "Bearer",
                      BearerFormat = "JWT",
                      In = Microsoft.OpenApi.Models.ParameterLocation.Header,
                      Description =
                          "Enter 'Bearer' [space] and then your token in the text input below.\n\nExample: 'Bearer 12345abcdef'",
                  }
              );

              options.AddSecurityRequirement(
                  new Microsoft.OpenApi.Models.OpenApiSecurityRequirement
                  {
                      {
                          new Microsoft.OpenApi.Models.OpenApiSecurityScheme
                          {
                              Reference = new Microsoft.OpenApi.Models.OpenApiReference
                              {
                                  Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme,
                                  Id = "Bearer",
                              },
                          },
                          new string[] { }
                      },
                  }
              );
          });
          context.Services.AddHttpClient(
              "catos",
              (sp, client) =>
              {
                  var scenarioManager = sp.GetRequiredService<ScenarioManager>();

                  var configuration = sp.GetRequiredService<IConfiguration>();
                  client.BaseAddress = new Uri(
                      configuration.GetValue<string>("RemoteServices:Default:BaseUrl")
                  );
                  var jwtToken = scenarioManager.GetOrCreate().StringData[
                      ScenarioContext.AccessToken
                  ];
                  client.DefaultRequestHeaders.Authorization =
                      new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", jwtToken);
              }
          );
      }

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

    hi

    Please share full code of your CatOsHttpApiClientTestModule

    It needs to depends on AbpHttpClientModule

  • User Avatar
    0
    sinancondo created

    Full class , and I am already depending on the mentioned module :

    [DependsOn(
        typeof(AbpAutofacModule),
        typeof(AbpHttpClientModule), //used to create client proxies
        typeof(CatOsApplicationContractsModule), //used to create client proxies,
        typeof(AbpAspNetCoreModule),
        typeof(CatOsHttpApiClientModule)
    )]
    public class CatOsHttpApiClientTestModule : AbpModule
    {
        private readonly string RemoteServiceName = "Default";
    
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddHttpClientProxies(
                typeof(CatOsApplicationContractsModule).Assembly,
                RemoteServiceName
            );
    
            context.Services.AddAutofac();
            context.Services.AddControllers();
            context.Services.AddEndpointsApiExplorer();
            context.Services.AddHttpContextAccessor();
            context.Services.AddScoped<ScenarioManager>();
            context.Services.AddSwaggerGen(options =>
            {
                options.AddSecurityDefinition(
                    "Bearer",
                    new Microsoft.OpenApi.Models.OpenApiSecurityScheme
                    {
                        Name = "Authorization",
                        Type = Microsoft.OpenApi.Models.SecuritySchemeType.Http,
                        Scheme = "Bearer",
                        BearerFormat = "JWT",
                        In = Microsoft.OpenApi.Models.ParameterLocation.Header,
                        Description =
                            "Enter 'Bearer' [space] and then your token in the text input below.\n\nExample: 'Bearer 12345abcdef'",
                    }
                );
    
                options.AddSecurityRequirement(
                    new Microsoft.OpenApi.Models.OpenApiSecurityRequirement
                    {
                        {
                            new Microsoft.OpenApi.Models.OpenApiSecurityScheme
                            {
                                Reference = new Microsoft.OpenApi.Models.OpenApiReference
                                {
                                    Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme,
                                    Id = "Bearer",
                                },
                            },
                            new string[] { }
                        },
                    }
                );
            });
            context.Services.AddHttpClient(
                "catos",
                (sp, client) =>
                {
                    var scenarioManager = sp.GetRequiredService<ScenarioManager>();
    
                    var configuration = sp.GetRequiredService<IConfiguration>();
                    client.BaseAddress = new Uri(
                        configuration.GetValue<string>("RemoteServices:Default:BaseUrl")
                    );
                    var jwtToken = scenarioManager.GetOrCreate().StringData[
                        ScenarioContext.AccessToken
                    ];
                    client.DefaultRequestHeaders.Authorization =
                        new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", jwtToken);
                }
            );
        }
    
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env = context.GetEnvironment();
            // Configure the HTTP request pipeline.
            if (env.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }
    
            app.UseHttpsRedirection();
    
            // app.UseAuthorization();
    
            app.UseRouting(); // Added to enable endpoint routing
    
            app.UseEndpoints(endpoints => // Updated to use IEndpointRouteBuilder
            {
                endpoints.MapControllers();
            });
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share a minimal project to reproduce?

    Thanks.

    liming.ma@volosoft.com

  • User Avatar
    0
    sinancondo created

    I fixed that issue , but still failing to run the application, now getting this one :

  • User Avatar
    0
    sinancondo created

    The dynamic proxy interface cannot be resolved I have sent you the project by email , please let me know if you need anything else

    `fail: Volo.Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter[0] ---------- RemoteServiceErrorInfo ---------- { "code": null, "message": "An internal error occurred during your request!", "details": null, "data": null, "validationErrors": null }

    fail: Volo.Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter[0] An exception was thrown while activating Cao.CatOs.TestHarness.Api.Host.Features.CatFile.CatFileSummaryTestService. Autofac.Core.DependencyResolutionException: An exception was thrown while activating Cao.CatOs.TestHarness.Api.Host.Features.CatFile.CatFileSummaryTestService. ---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'Cao.CatOs.TestHarness.Api.Host.Features.CatFile.CatFileSummaryTestService' can be invoked with the available services and parameters: Cannot resolve parameter 'Cao.CatOs.CatFiles.ICatFileSummaryAppService catFileAppService' of constructor 'Void .ctor(Cao.CatOs.CatFiles.ICatFileSummaryAppService)'.

    See https://autofac.rtfd.io/help/no-constructors-bindable for more info. at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass14_0.

    trce: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[53] Exception Filter: After executing OnExceptionAsync on filter Volo.Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter. `

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ok, I will check your project.

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.2.0-preview. Updated on January 09, 2026, 07:22
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.