解决方案由于缺少OperationFilterContext.ControllerActionDescriptor而无法编译

Bri*_*off 2 c# swashbuckle asp.net-core aspnetboilerplate

我刚刚创建并下载了一个示例项目。由于引用ControllerActionDescriptorOperationFilterContext对象的属性,因此无法编译:

public class SecurityRequirementsOperationFilter : IOperationFilter
{
    public void Apply(Operation operation, OperationFilterContext context)
    {
        var actionAttrs = context.ControllerActionDescriptor.MethodInfo.GetCustomAttributes(true).ToList();
    }
}
Run Code Online (Sandbox Code Playgroud)

我确实更新了所有NuGet软件包。DLL的地狱永远不会消失:-(

aar*_*ron 7

Swashbuckle.AspNetCore v2.5.0

ControllerActionDescriptor仅在Swashbuckle.AspNetCorev2.5.0中提供。

参见:https : //github.com/domaindrivendev/Swashbuckle.AspNetCore/commit/c9777021ff3b7bd7900fb259779df8d3cba4e217#diff-e86edb6a6357b96238665ca2b11f5ab8


Swashbuckle.AspNetCore v3.0.0 +

现在,您只需要:

var controllerAttributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true);
Run Code Online (Sandbox Code Playgroud)