使用api版本控制的Autofac和swagger给出了例外

Fre*_*nke 5 .net c# autofac swagger asp.net-core

从visual studio运行我的项目时,我得到以下异常,它是一个ASP.NET核心项目.

似乎依赖项被注册两次,因此"System.ArgumentException:已经添加了具有相同键的项目".

它似乎也与路由有关,但我找不到调试它的方法.

它似乎也与Api中的Versioning有关,因为如果删除此代码,异常就会消失.

services.AddApiVersioning(o =>
        {
            o.AssumeDefaultVersionWhenUnspecified = true;
            o.DefaultApiVersion = new ApiVersion(1, 0);
            o.ReportApiVersions = true;
            o.ApiVersionSelector = new CurrentImplementationApiVersionSelector(o);
        });
Run Code Online (Sandbox Code Playgroud)

任何人都见过这个或者想知道如何调试它.

Autofac.Core.DependencyResolutionException:激活特定注册期间发生错误.有关详细信息,请参阅内部异常 注册:Activator = ISwaggerProvider(DelegateActivator),Services = [Swashbuckle.AspNetCore.Swagger.ISwaggerProvider],Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime,Sharing = None,Ownership = OwnedByLifetimeScope激活特定注册期间发生错误.有关详细信息,请参阅内部异常 注册:Activator = ApiDescriptionGroupCollectionProvider(ReflectionActivator),Services = [Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider],Lifetime = Autofac.Core.Lifetime.RootScopeLifetime,Sharing = Shared,Ownership = OwnedByLifetimeScope激活特定注册时发生错误.有关详细信息,请参阅内部异常 注册:Activator = IApiDescriptionProvider [](DelegateActivator),Services = [System.Collections.Generic.IEnumerable 1[[Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionProvider, Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DefaultApiDescriptionProvider (ReflectionActivator), Services = [Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionProvider], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DefaultInlineConstraintResolver (ReflectionActivator), Services = [Microsoft.AspNetCore.Routing.IInlineConstraintResolver], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope An exception was thrown while invoking the constructor 'Void .ctor(Microsoft.Extensions.Options.IOptions1 [Microsoft.AspNetCore.Routing.RouteOptions])'类型'DefaultInlineConstraintResolver'.已添加具有相同键的项目.(有关详细信息,请参阅内部异常.)(有关详细信息,请参阅内部异常.)(有关详细信息,请参阅内部异常.)(有关详细信息,请参阅内部异常.)(有关详细信息,请参阅内部异常.)

Box*_*xed 0

尝试添加此代码:

services.AddMvcCore().AddVersionedApiExplorer(
                opt =>
                {
                    opt.GroupNameFormat = "'v'VVV";

                    opt.SubstituteApiVersionInUrl = true;
                });
Run Code Online (Sandbox Code Playgroud)