question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can only set applicationScopedServiceProvider once

See original GitHub issue

Version 3.1.0

Since 3.1.0, our web applications that use Autofac have been experiencing this error: Can only set applicationScopedServiceProvider once

I can try and create a repro solution if needed, but just wanted to check first to see whether there is anything obvious I can do to resolve the issue? When debugging into the symbols, both the _applicationScopedServiceProvider and the serviceProvider passed in are instances of AutofacServiceProvider but they must be different because it’s passing the != check.

Version 3.0.0 does not have this issue. Our micro-services projects (that don’t use Autofac) don’t have this issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
koenbeukcommented, Jun 28, 2022

I just released a new version on NuGet, can you try using that version and see if it solves your issue? https://www.nuget.org/packages/EntityFrameworkCore.Triggered/3.2.0-preview.3 (Should appear any minute from now)

2reactions
benmccallumcommented, Jun 27, 2022

This appears to be due to the combination of EFC.Triggered and Autofac. I’ve created a repro here.

3.0.0 issue with MediatR On 3.0.0, we have an intermittent issue with the service provider being disposed before MediatR can spawn a notification handler from it.

System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed.

Repro:

  1. Checkout commit 20da48c308aaf18bb9490ba7e68685e8e19c80ec
  2. Do a POST to https://localhost:5001/api/course/add - works
  3. Do a second POST to the same url - fails.

3.1.0 issue Bump to 3.1.0 and above issue is fixed, but only when Autofac isn’t involved.

Introduce Autofac and 3.1.0, and we get the issue Anth report here.

System.InvalidOperationException: Can only set applicationScopedServiceProvider once

To repro:

  1. Checkout commit a2bf5962ca62bd534ef05c3737ef0f0fe9c0b09e
  2. Do a POST to https://localhost:5001/api/course/add - instant failure

Path forward Options:

  1. Fix in EFC.Triggered or Autofac, wherever the problem lies?
  2. We remove Autofac and move onto MS DI (a pretty big change for us, but do-able).

Keen to hear your thoughts @koenbeuk now that you could reproduce it and have a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ApplicationServices resolves a different scoped instance in ...
ApplicationServices and not realizing that it is application scoped (global), instead of being scoped to HTTP request, by default, ASP.NET Core ...
Read more >
Using Contexts and Dependency Injection for the Java EE ...
The CDI specification defines a set of services for using injection to specify dependencies in an application. CDI provides contextual life cycle management ......
Read more >
Oracle REST Data Services Java API Reference
Providers can have one of two life-cycles: @ApplicationScoped - instantiated when the ORDS is started by an application server, destroyed when the application ......
Read more >
Using HostBuilder, ServiceProvider and Dependency Injection ...
First of all, after creating a .NET Core Windows Forms application, we need to add the NuGet package Microsoft.Extensions.Hosting to the project ...
Read more >
aries-cdi/faq.md at master
The @Service annotation on the bean type may specify a set of types as an argument of the annotation. ... @ApplicationScoped can only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found