Using the ServerApplicationContext in an assembly that references the application server project.

Locked Using the ServerApplicationContext in an assembly that references the application server project.

  • 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?

    thx


    paul van bladel


All Replies

  • Monday, November 19, 2012 3:58 PM
     
     Answered

    Hi Paul,

    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.

    Eric


    http://blogs.msdn.com/b/eric_erhardt/

  • Monday, November 19, 2012 7:24 PM
     
     

    http://blogs.msdn.com/b/lightswitch/archive/2012/11/19/a-new-api-for-lightswitch-server-interaction-the-serverapplicationcontext.aspx

    Joe Binder just posted a blog on this topic.  See the section title "Security restrictions" near the end.

    Hope this helps,

    Eric


    http://blogs.msdn.com/b/eric_erhardt/