I raised a previous post about SaveAsync() not working. I boiled this down to a configuration setting..."CslaAutoCloneOnUpdate" if this is false then SaveAsync doesn't work. I have test cases to validate. I know this is a legacy setting but there are aspects of our code that require this until they can be fixed.
Secondly if calling SaveAsync() in an asp.net Web API controller in my test case. After the call HttpContext is null. Before the call it's fine. This pretty much breaks everything as the user has no identity.
I've had issues with threading before with CSLA background workers but never where HttpContext becomes null?
As a work around, can you use use the sync version of Save in your controller?
For your HttpContext becoming null, is that in your controller method or is it when you try to use HttpContext from your BO classes? If its the latter, its because HttpContext is specific to the request thread I believe, and your BO is now on a different thread, so I wouldn't expect it to transition. You'd have to set your async code to bring along the principal or do it manually. I think there was a thread here about this recently.
Yes, I should have realised that HttpContext would become null when the await returned.
Yes I can do sync save without problem. And I can do Async save if I remove the AutoCloneOnUpdate=false.
http://vegetarianprogrammer.blogspot.cz/2012/12/understanding-synchronizationcontext-in.html - try set ASP.NET "task friendly synchronization context"
Copyright (c) Marimer LLC