Skip to content

NullReferenceException in PersistedGrantRepository #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Skoucail opened this issue May 17, 2019 · 3 comments · Fixed by #287
Closed

NullReferenceException in PersistedGrantRepository #279

Skoucail opened this issue May 17, 2019 · 3 comments · Fixed by #287
Assignees
Labels
bug Something isn't working

Comments

@Skoucail
Copy link

Skoucail commented May 17, 2019

When calling the function GetPersistedGrantsByUsersAsync from the PersistedGrantRepository with a search parameter i get a NullReferenceException.
Seeing the code i guess the problem is that SubjectName in x.SubjectName.Contains(search) is null.

I'm not using identity, so cant use the PersistedGrantAspNetIdentityRepository. But in the PersistedGrantAspNetIdentityRepository SubjectName is getting filled from the asp.net identity source and the search seems to work.

Stack trace:

2019-05-17 17:24:59.514 +02:00 [ERR] An exception occurred while iterating over the results of a query for context type 'IdentityServerAdmin.Admin.EntityFramework.DbContexts.IdentityServerPersistedGrantDbContext'.
System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , PersistedGrantDataView )
   at System.Linq.AsyncEnumerable.WhereEnumerableAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Where.cs:line 110
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at System.Linq.AsyncEnumerable.TakeAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Take.cs:line 119
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor'1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , PersistedGrantDataView )
   at System.Linq.AsyncEnumerable.WhereEnumerableAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Where.cs:line 110
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at System.Linq.AsyncEnumerable.TakeAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Take.cs:line 119
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor'1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
2019-05-17 17:24:59.576 +02:00 [ERR] An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , PersistedGrantDataView )
   at System.Linq.AsyncEnumerable.WhereEnumerableAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Where.cs:line 110
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at System.Linq.AsyncEnumerable.TakeAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Take.cs:line 119
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor'1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable'1 source, TAccumulate seed, Func'3 accumulator, Func'2 resultSelector, CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Aggregate.cs:line 120
   at Skoruba.IdentityServer4.Admin.BusinessLogic.Repositories.PersistedGrantRepository'1.GetPersistedGrantsByUsersAsync(String search, Int32 page, Int32 pageSize)
   at Skoruba.IdentityServer4.Admin.BusinessLogic.Services.PersistedGrantService.GetPersistedGrantsByUsersAsync(String search, Int32 page, Int32 pageSize)
   at IdentityServerAdmin.Admin.Controllers.GrantController.PersistedGrants(Nullable'1 page, String search) in E:\git\alsic\IdentityServer4\IdentityServerAdmin\src\IdentityServerAdmin.Admin\Controllers\GrantController.cs:line 32
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask'1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.CspMiddleware.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
2019-05-17 17:24:59.623 +02:00 [ERR] Exception at route /Grant/PersistedGrants
System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , PersistedGrantDataView )
   at System.Linq.AsyncEnumerable.WhereEnumerableAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Where.cs:line 110
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at System.Linq.AsyncEnumerable.TakeAsyncIterator'1.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Take.cs:line 119
   at System.Linq.AsyncEnumerable.AsyncIterator'1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor'1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable'1 source, TAccumulate seed, Func'3 accumulator, Func'2 resultSelector, CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Aggregate.cs:line 120
   at Skoruba.IdentityServer4.Admin.BusinessLogic.Repositories.PersistedGrantRepository'1.GetPersistedGrantsByUsersAsync(String search, Int32 page, Int32 pageSize)
   at Skoruba.IdentityServer4.Admin.BusinessLogic.Services.PersistedGrantService.GetPersistedGrantsByUsersAsync(String search, Int32 page, Int32 pageSize)
   at IdentityServerAdmin.Admin.Controllers.GrantController.PersistedGrants(Nullable'1 page, String search) in E:\git\alsic\IdentityServer4\IdentityServerAdmin\src\IdentityServerAdmin.Admin\Controllers\GrantController.cs:line 32
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask'1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.CspMiddleware.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
@skoruba
Copy link
Owner

skoruba commented May 17, 2019

Can you please share whole exception - with more details?
Thanks!

@skoruba skoruba self-assigned this May 17, 2019
@Skoucail
Copy link
Author

Can you please share whole exception - with more details?
Thanks!

I added the stack trace.

@skoruba skoruba added the bug Something isn't working label May 17, 2019
@skoruba
Copy link
Owner

skoruba commented May 26, 2019

I fixed it on dev branch, please check it. For this implementation - the subject name is not available - so I removed the SubjectName from filtering and set up to string.Empty for view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants