Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Exception when using the new DI activated options style cookie auth #72

Closed
borgdylan opened this issue Oct 9, 2014 · 10 comments
Closed

Comments

@borgdylan
Copy link

After updating to newest security packages, I get the following exception:

System.AggregateException: One or more errors occurred ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: provider
  at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetService[ILoggerFactory] (IServiceProvider provider) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Builder.RouterMiddleware.EnsureLogger (Microsoft.AspNet.Http.HttpContext context) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Builder.RouterMiddleware+<Invoke>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Security.Infrastructure.AuthenticationMiddleware`1+<Invoke>d__1[Microsoft.AspNet.Security.Cookies.CookieAuthenticationOptions].MoveNext () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
 --> (Inner exception 0) System.ArgumentNullException: Argument cannot be null.
Parameter name: provider
  at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetService[ILoggerFactory] (IServiceProvider provider) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Builder.RouterMiddleware.EnsureLogger (Microsoft.AspNet.Http.HttpContext context) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Builder.RouterMiddleware+<Invoke>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Security.Infrastructure.AuthenticationMiddleware`1+<Invoke>d__1[Microsoft.AspNet.Security.Cookies.CookieAuthenticationOptions].MoveNext () [0x00000] in <filename unknown>:0 
@borgdylan
Copy link
Author

This bug does not let my app run at all as all requests return an internal server error.

@Tratcher
Copy link
Member

Tratcher commented Oct 9, 2014

I don't think this is related to the security middleware changes, the exception is coming from here:
https://github.com/aspnet/Routing/blob/dev/src/Microsoft.AspNet.Routing/RouterMiddleware.cs#L61

@yishaigalatzer Do you know where this logging resolution pattern came from? It's not how we do it anywhere else. See CookieAuthMiddleware & Extensions for a better example.

@Tratcher
Copy link
Member

Tratcher commented Oct 9, 2014

@borgdylan It looks like RequestServices is null. Do you still have a call to UseServices in your startup?

Also: aspnet/Hosting#88

@Tratcher
Copy link
Member

Tratcher commented Oct 9, 2014

@HaoK

@borgdylan
Copy link
Author

I am no longer calling ContainerExtensions.UseServices. I am using ConfigureServices in my Startup class. Should I revert back for now?

@HaoK
Copy link
Member

HaoK commented Oct 9, 2014

Using ConfigureServices is fine, but you still need UseServices to actually use the services you configured

@HaoK
Copy link
Member

HaoK commented Oct 9, 2014

The UseServices() with no parameters is what you want to use to automatically use the Configured services

@borgdylan
Copy link
Author

That fixed the issue. Thanks

@Tratcher
Copy link
Member

Tratcher commented Oct 9, 2014

I'm still going to open a bug against RouterMiddleware, logging shouldn't be resolved that way.

@borgdylan
Copy link
Author

Indeed. Adding an ILoggerFactory in ConfigureServices still causes the exception without UseServices

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants