Skip to content
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

WebApi: Attempt to end a scope before all child scopes are completed. #153

Closed
paiden opened this issue Jan 7, 2015 · 4 comments
Closed

Comments

@paiden
Copy link

paiden commented Jan 7, 2015

I'm using LightInject in a ASP.NET WebApi project. When the API call exits, I sometimes get the error:
System.InvalidOperationException occurred
HResult=-2146233079
Message=Attempt to end a scope before all child scopes are completed.
Source=LightInject
StackTrace:
at LightInject.ScopeManager.EndScope(Scope scope) in c:\Users\bri\Documents\GitHub\LightInject\NuGet\Build\Net45\LightInject\LightInject.cs:line 4727
InnerException:
Additional information: Attempt to end a scope before all child scopes are completed.

I currently have no clue why I get this error.

More information about my project:

  • LighInject v3.0.2.1
  • LightInject.WebApi v1.0.0.3
  • WebApi 2.1
  • WebApi is self hosted in console
  • Container setup:
    var container = new ServiceContainer();
    container.RegisterApiControllers(CustomAssemblyResolver.GetControllerAssemblies().ToArray());
    Bootstrapper.Bootstrap(container); //performs service registration 
    container.EnableWebApi(config);
@seesharper
Copy link
Owner

Try this

container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();

@paiden
Copy link
Author

paiden commented Jan 7, 2015

That did the trick. Now that you mentioned the scope manager I also found the 'Async/Await 'and 'OWIN selfhosting' sections in the documentation that would have pointed me into the right direction.

Thank you very much for your help.

@seesharper
Copy link
Owner

You're welcome:)

On Wednesday, January 7, 2015, paiden notifications@github.com wrote:

That did the trick. Now that you mentioned the scope manager I also found
the 'Async/Await 'and 'OWIN selfhosting' sections in the documentation that
would have pointed me into the right direction.

Thank you very much for your help.


Reply to this email directly or view it on GitHub
#153 (comment)
.

@0xced
Copy link
Contributor

0xced commented Sep 26, 2018

@seesharper I just got bitten by this too. Would you accept a pull request that makes PerLogicalCallContextScopeManagerProvider the default ScopeManagerProvider on target frameworks where it's available ? Do you think it makes sense ?

0xced added a commit to 0xced/LightInject that referenced this issue Sep 26, 2018
On target frameworks where it’s available, default to using `PerLogicalCallContextScopeManagerProvider` instead of `PerThreadScopeManagerProvider`.

See also seesharper#153.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants