Application startup exception: System.InvalidOperationException: Cannot resolve scoped service from root provider


Error: Application startup exception: System.InvalidOperationException: Cannot resolve scoped service from root provider.

Solution: There is a chance that you are trying to inject a Service into an Asp.Net Core 3.1 Middleware through a constructor. Instead of injecting a Service Interface through a Middleware Constructor, inject it through an invoke method/function like so:

 public async Task Invoke(HttpContext context, IAnalytics analytics)
        {

//Then use your Service in here

analytics.SomeFunction();

}
  • The service will be available to the Application when the Service Container is loaded.

    Let me know if this solves your problem by leaving me a review below: You can comment without creating an account or just like this article is this helped solve your problem.






For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email Address[email protected]