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

时间:2018-09-10 15:56:54

标签: c# asp.net-core aspnetboilerplate swashbuckle

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

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

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

1 个答案:

答案 0 :(得分:6)

Swashbuckle.AspNetCore v2.5.0

ControllerActionDescriptor仅存在于Swashbuckle.AspNetCore v2.5.0中。

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


Swashbuckle.AspNetCore v3.0.0 +

现在,您只需要:

var controllerAttributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true);