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

Error when using async routes #27

Open
michael-wolfenden opened this issue Aug 6, 2014 · 2 comments
Open

Error when using async routes #27

michael-wolfenden opened this issue Aug 6, 2014 · 2 comments

Comments

@michael-wolfenden
Copy link

I am getting an error when using an async route for my homepage:

Get["/", true] = async (_, __) => await RenderHomepage();
System.NullReferenceException was unhandled by user code
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Cassette.Nancy
  StackTrace:
       at Cassette.Nancy.NancyContextLifetimeProvider.GetObject() in c:\development\Cassette.Nancy\src\Cassette.Nancy\NancyContextLifetimeProvider.cs:line 20
       at Cassette.TinyIoC.TinyIoCContainer.CustomObjectLifetimeFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options)
       at Cassette.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options)
  InnerException: 

I believe the issue is due to the NancyContext being stored as a ThreadLocal. The response is being returned on a different thread due to async and so the call to getContext() is returning null as we set the context on a different thread.

@mattyway
Copy link

I'm also running into this issue.

@michael-wolfenden Did you find a workaround?

@michael-wolfenden
Copy link
Author

@mattyway.. Nope, ended up using SquishIt which is a shame as this is a much simpler / nicer library

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

2 participants