HybridWebThreadScopeInfo and Mono

53 views
Skip to first unread message

bluesliverx

unread,
Jun 14, 2010, 6:04:28 PM6/14/10
to Castle Project Users
Hello all,

No matter what I try, I can't seem to get the hybrid web scope working
with an asynchronous action when using Mono (tested on 2.6.1, 2.6.3,
and 2.6.4). Each time I get a NullRefEx in either the OnEndRequest
method or the SessionScopeWebModule. Here is the stacktrace running
locally on a windows machine using XSP2:

System.NullReferenceException: Object reference not set to an instance
of an object
at [MyApp].Global.OnEndRequest (System.Object sender,
System.EventArgs e) [0x00000] in <filename unknown>:0
at (wrapper delegate-invoke)
System.EventHandler:invoke_void__this___object_EventArgs
(object,System.EventArgs)
at (wrapper delegate-invoke)
System.EventHandler:invoke_void__this___object_EventArgs
(object,System.EventArgs)
at (wrapper delegate-invoke)
System.EventHandler:invoke_void__this___object_EventArgs
(object,System.EventArgs)
at System.Web.HttpApplication.PipelineDone () [0x0001c] in C:\cygwin
\tmp\monobuild\build\BUILD\mono-2.6.4\mcs\class\System.Web\System.Web
\HttpApplication.cs:1106

Here is the same stack trace using mod_mono on Ubuntu, notice on this
one I was using the SessionScopeWebModule:

System.NullReferenceException: Object reference not set to an instance
of an object
at Castle.ActiveRecord.Framework.SessionScopeWebModule.OnEndRequest
(System.Object sender, System.EventArgs e) [0x00000] in <filename
unknown>:0
at (wrapper delegate-invoke)
System.EventHandler:invoke_void__this___object_EventArgs
(object,System.EventArgs)
at System.Web.HttpApplication.PipelineDone () [0x00000] in <filename
unknown>:0

I tried both methods (writing my own OnBegin/OnEndRequest methods and
SessionScopeWebModule) since I thought it may at first have been the
module causing the problem.

The asynchronous action is a simple example:

public class TasksController : ARSmartDispatchController {
public TasksController()
: base() {
asynctestTask = AsyncTestTaskRun;
}
private delegate string AsyncTestTask();
private readonly AsyncTestTask asynctestTask;
private string AsyncTestTaskRun() {
System.Threading.Thread.Sleep(250);
return "Async Test Finished Successfully";
}

public IAsyncResult BeginAsyncTest() {
return asynctestTask.BeginInvoke(ControllerContext.Async.Callback,
ControllerContext.Async.State);
}

public void EndAsyncTest() {
Flash["message"] =
asynctestTask.EndInvoke(ControllerContext.Async.Result);
RedirectToAction("index");
}
}

Any ideas on this one? I've tried many things to get this working,
and I do have the HybridWebThreadScopeInfo configured on my
activerecord:
<activerecord isWeb="true"
threadinfotype="Castle.ActiveRecord.Framework.Scopes.HybridWebThreadScopeInfo,
Castle.ActiveRecord">
....
</activerecord>

Thanks!
-Brian

bluesliverx

unread,
Jun 23, 2010, 3:40:47 PM6/23/10
to Castle Project Users
After some more digging, I've tracked the problem down to the fact
that HttpContext.Current is null. Somehow, Context (in the
OnEndRequest method in my global application) is still non-null, but
if I attempt to remove the scope from there, it tells me that it is
not the currently registered scope. This works fine when compiling in
VS2010, but not under mono in Windows or Linux. As I'm not an expert
in ASP.NET and Mono, I'm at a standstill with async methods until I
can figure this out.

Perhaps I could ask everyone a different question: I can merely check
to see if HttpContext.Current is null and then skip disposing of the
scope if it is. Will this leave open connections to the database or
have performance or other implications if I don't dispose of the
correct scope?

Thanks for your help,
Brian

bluesliverx

unread,
Jun 24, 2010, 12:48:14 PM6/24/10
to Castle Project Users
For anyone who runs into the same problem, I finally found that the
HttpContext variable within the controller EndAsyncTest() method was
being set correctly, but HttpContext.Current was null for some reason.
By putting "HttpContext.Current = HttpContext;" in the EndAsyncTest()
method at any point, the scope was able to be successfully disposed of
using my own OnEndRequest method or the SessionScopeWebModule:

public void EndAsyncTest() {
HttpContext.Current = HttpContext;
Flash["message"] =
asynctestTask.EndInvoke(ControllerContext.Async.Result);
RedirectToAction("index");
}

Thanks,
Brian

Roelof Blom

unread,
Jun 25, 2010, 4:41:55 AM6/25/10
to castle-pro...@googlegroups.com
Thanks for the feedback Brian.

-- Roelof.


--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.


Reply all
Reply to author
Forward
0 new messages