NRE in GetPolicyRequirements()
VictorioBerra opened this issue · 2 comments
Bare with me here, because I dont have a TON of information because I am encountering this error when I use another library called PolicyServer.
The NRE happens on this line:
https://github.com/Dotnet-Boxed/Framework/blob/master/Source/Boxed.AspNetCore.Swagger/FilterDescriptorExtensions.cs#L25
I get an NRE on that line, Policy
is null because of the above library. I think we need to code more defensively here somehow. I believe the error is somewhere in here https://github.com/PolicyServer/PolicyServer.Local/blob/dev/src/PolicyServer.Local/AspNetCore/AuthorizationPolicyProvider.cs
Somehow, PolicyServer is creating its own handler and requirements. But I am not sure whats wrong. Why would Policy be blank? Maybe there is no policy? I mentioned this over in https://github.com/PolicyServer/PolicyServer.Local/issues/17
This might be the fault of using an auth attribute without any policy. IE: [Authorize]
.
I found if I apply global authorization to my app, I do not get this error. But if I try and use PolicyServer via [Authorize("myPermission")]
it blows up again:
Unhandled Exception
System.NullReferenceException: Object reference not set to an instance of an object.
at Boxed.AspNetCore.Swagger.FilterDescriptorExtensions.GetPolicyRequirements(IList`1 filterDescriptors) in C:\projects\framework\Source\Boxed.AspNetCore.Swagger\FilterDescriptorExtensions.cs:line 25
at Boxed.AspNetCore.Swagger.OperationFilters.ForbiddenResponseOperationFilter.Apply(Operation operation, OperationFilterContext context) in C:\projects\framework\Source\Boxed.AspNetCore.Swagger\OperationFilters\ForbiddenResponseOperationFilter.cs:line 30
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.<>c__DisplayClass5_0.<CreatePathItems>b__2(IGrouping`2 group)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at MyApp.API.Errors.ErrorHandlingMiddleware.Invoke(HttpContext context) in C:\Source\MyApp\src\MyApp.API\Errors\ErrorHandlingMiddleware.cs:line 26
Thanks, merged.