You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Method not found: 'System.Threading.Tasks.Task`1<System.Collections.Generic.List`1<Ocelot.Values.Service>> Ocelot.ServiceDiscovery.Providers.IServiceDiscoveryProvider.Get()'.
The reason is that .NET8-Ocelot[20.*] renamed the [Ocelot.ServiceDiscovery.Providers.IServiceDiscoveryProvider.Get] method to [Ocelot.ServiceDiscovery.Providers.IServiceDiscoveryProvider.GetAsync].
Modify line 97 in the file 'Src\MMLib.SwaggerForOcelot\ServiceDiscovery\SwaggerServiceDiscoveryProvider.cs'
ServiceHostAndPort service = (await serviceProvider.Data.GetAsync()).FirstOrDefault()?.HostAndPort;
to
ServiceHostAndPort service = (await serviceProvider.Data.Get()).FirstOrDefault()?.HostAndPort;
fix the error.
The temporary fix is as follows:
/// <summary>/// In your project, create a new class and implement the interface ISwaggerServiceDiscoveryProvider./// </summary>publicclassMySwaggerServiceDiscoveryProvider:ISwaggerServiceDiscoveryProvider{privatereadonlyIServiceDiscoveryProviderFactory_serviceDiscovery;privatereadonlyIServiceProviderConfigurationCreator_configurationCreator;privatereadonlyIOptionsMonitor<FileConfiguration>_options;privatereadonlyIHttpContextAccessor_httpContextAccessor;privatereadonlyIOptions<SwaggerOptions>_swaggerOptions;publicMySwaggerServiceDiscoveryProvider(IServiceDiscoveryProviderFactoryserviceDiscovery,IServiceProviderConfigurationCreatorconfigurationCreator,IOptionsMonitor<FileConfiguration>options,IHttpContextAccessorhttpContextAccessor,IOptions<SwaggerOptions>swaggerOptions){_serviceDiscovery=serviceDiscovery;_configurationCreator=configurationCreator;_options=options;_httpContextAccessor=httpContextAccessor;_swaggerOptions=swaggerOptions;}/// <inheritdoc />publicasyncTask<Uri>GetSwaggerUriAsync(SwaggerEndPointConfigendPoint,RouteOptionsroute){if(endPoint.Version=="aggregates"||endPoint.Version=="gateway"){returnGetGatewayItSelfSwaggerPath(endPoint);}elseif(!endPoint.Url.IsNullOrEmpty()){returnnewUri(endPoint.Url);}else{returnawaitGetSwaggerUri(endPoint,route);}}privateUriGetGatewayItSelfSwaggerPath(SwaggerEndPointConfigendPoint){if(_httpContextAccessor.HttpContextisnull)thrownewInvalidOperationException(GetErrorMessage(endPoint));varbuilder=newUriBuilder(_httpContextAccessor.HttpContext.Request.Scheme,_httpContextAccessor.HttpContext.Request.Host.Host){Path=_swaggerOptions.Value.RouteTemplate.Replace("{documentName}",endPoint.Version).Replace("{json|yaml}","json")};if(_httpContextAccessor.HttpContext.Request.Host.Port.HasValue&&_httpContextAccessor.HttpContext.Request.Host.Portis not null){builder.Port=_httpContextAccessor.HttpContext.Request.Host.Port.Value;}returnbuilder.Uri;}privateasyncTask<Uri>GetSwaggerUri(SwaggerEndPointConfigendPoint,RouteOptionsroute){varconf=_configurationCreator.Create(_options.CurrentValue.GlobalConfiguration);vardownstreamRoute=newDownstreamRouteBuilder().WithUseServiceDiscovery(true).WithServiceName(endPoint.Service.Name).WithServiceNamespace(route?.ServiceNamespace).Build();Response<IServiceDiscoveryProvider>serviceProvider=_serviceDiscovery.Get(conf,downstreamRoute);if(serviceProvider.IsError){thrownewInvalidOperationException(GetErrorMessage(endPoint));}ServiceHostAndPort?service=((awaitserviceProvider.Data.GetAsync()).FirstOrDefault()?.HostAndPort)??thrownewInvalidOperationException(GetErrorMessage(endPoint));varbuilder=newUriBuilder(GetScheme(service,route),service.DownstreamHost,service.DownstreamPort){Path=endPoint.Service.Path};returnbuilder.Uri;}privatestringGetScheme(ServiceHostAndPortservice,RouteOptionsroute)=>(route!=null&&!route.DownstreamScheme.IsNullOrEmpty())?route.DownstreamScheme:!service.Scheme.IsNullOrEmpty()?service.Scheme:service.DownstreamPortswitch{443=>Uri.UriSchemeHttps,80=>Uri.UriSchemeHttp,
_ =>string.Empty,};privatestaticstringGetErrorMessage(SwaggerEndPointConfigendPoint)=>$"Service with swagger documentation '{endPoint.Service.Name}' cann't be discovered";}
services.AddSwaggerForOcelot(builder.Configuration);//Add below the injection of MMLib.SwaggerForOcelot.services.Replace(newServiceDescriptor(typeof(ISwaggerServiceDiscoveryProvider),typeof(MySwaggerServiceDiscoveryProvider),ServiceLifetime.Transient));
The text was updated successfully, but these errors were encountered:
Using .NET8-Ocelot[20.*] will cause an exception:
The reason is that .NET8-Ocelot[20.*] renamed the [Ocelot.ServiceDiscovery.Providers.IServiceDiscoveryProvider.Get] method to [Ocelot.ServiceDiscovery.Providers.IServiceDiscoveryProvider.GetAsync].
Modify line 97 in the file 'Src\MMLib.SwaggerForOcelot\ServiceDiscovery\SwaggerServiceDiscoveryProvider.cs'
to
fix the error.
The temporary fix is as follows:
The text was updated successfully, but these errors were encountered: