Saturday, November 17, 2012 7:39 AM
I'm trying to use the new ServerApplicationContext and I would like to use it in an assembly that has a binary reference to the Application Server project.
Everything compiles but I get following error: a server application context cannot be created from a thread that does not have a http context.
What do I need to do?
paul van bladel
- Edited by Paul Van Bladel Saturday, November 17, 2012 7:40 AM
Monday, November 19, 2012 3:58 PM
The issue here isn't becuase you are writing code in a different assembly. Instead, the problem is that you are invoking the middle tier using a protocol other than HTTP. Although we opened up the Server project so you can use other ASP.NET technologies to invoke LightSwitch business logic, we weren't able to completely remove our dependencies on the HttpContext. Thus, if you try to create a new ServerApplicationContext, and we can't find an HttpContext, we throw an exception.
In order to fix this, you need to set the System.Web.HttpContext.Current static property to a new "fake/mock" HttpContext. If you have Auth turned on, you will need to ensure the User property is initialized correctly, or LightSwitch won't know what user the code should run under.
Monday, November 19, 2012 7:24 PM
Joe Binder just posted a blog on this topic. See the section title "Security restrictions" near the end.
Hope this helps,