[Mono-dev] Problem with ASP.NET MVC 2: Flawed implementation of HttpServerUtility.Execute()?

Oskar Berggren oskar.berggren at gmail.com
Sun May 9 14:24:14 EDT 2010


Hi,

Summary: Mono's HttpServerUtility.Execute() seems to be a simplified
implementation that turns out to be incompatible with certain features
of ASP.Net MVC2. Or I'm doing something wrong. :)

I'm experimenting with ASP.NET MVC 2 and just added a call to
RenderAction(). This seems to show a problem with HttpServerUtility:

System.NullReferenceException: Object reference not set to an instance
of an object
  at System.Web.HttpServerUtility.Execute (IHttpHandler handler,
System.IO.TextWriter writer, Boolean preserveForm, System.String
exePath, System.String queryString, Boolean isTransfer, Boolean
isInclude) [0x00124] in
/home/oskar/mono24/mono-2.6.4/mono-2.6.4/mcs/class/System.Web/System.Web/HttpServerUtility.cs:184
  at System.Web.HttpServerUtility.Execute (IHttpHandler handler,
System.IO.TextWriter writer, Boolean preserveForm) [0x00011] in
/home/oskar/mono24/mono-2.6.4/mono-2.6.4/mcs/class/System.Web/System.Web/HttpServerUtility.cs:266
  at System.Web.HttpServerUtilityWrapper.Execute (IHttpHandler
handler, System.IO.TextWriter writer, Boolean preserveForm) [0x00000]
in /home/oskar/mono24/mono-2.6.4/mono-2.6.4/mcs/class/System.Web.Abstractions/System.Web/HttpServerUtilityWrapper.cs:111
  at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper
(System.Web.Mvc.HtmlHelper htmlHelper, System.String actionName,
System.String controllerName, System.Web.Routing.RouteValueDictionary
routeValues, System.IO.TextWriter textWriter) [0x00000] in <filename
unknown>:0
  at System.Web.Mvc.Html.ChildActionExtensions.RenderAction
(System.Web.Mvc.HtmlHelper htmlHelper, System.String actionName,
System.String controllerName, System.Web.Routing.RouteValueDictionary
routeValues) [0x00000] in <filename unknown>:0
  at System.Web.Mvc.Html.ChildActionExtensions.RenderAction
(System.Web.Mvc.HtmlHelper htmlHelper, System.String actionName,
System.String controllerName) [0x00000] in <filename unknown>:0
  at ASP.views_cwp_master.__RenderTree (System.Web.UI.HtmlTextWriter
__output, System.Web.UI.Control parameterContainer) [0x00000] in
<filename unknown>:0
  at System.Web.UI.Control.RenderChildren
(System.Web.UI.HtmlTextWriter writer) [0x0000b] in
/home/oskar/mono24/mono-2.6.4/mono-2.6.4/mcs/class/System.Web/System.Web.UI/Control.cs:1133
[... rest of normal asp.net and mvc2 stack trace omitted ...]


In Mono 2.6.4, around line 184 of HttpServerUtility.cs is this:

179 	if (!(handler is IHttpAsyncHandler)) {
180 	    handler.ProcessRequest (context);
181 	} else {
182 	    IHttpAsyncHandler asyncHandler = (IHttpAsyncHandler) handler;
183 	    IAsyncResult ar = asyncHandler.BeginProcessRequest (context,
null, null);
184 	    ar.AsyncWaitHandle.WaitOne ();
185 	    asyncHandler.EndProcessRequest (ar);
186 	}

I believe that AsyncWaitHandle is null here.

In this case, handler should be an instance of MvcHandler, which does
implement IHttpAsyncHandler. Its BeginProcessRequest() will detect
that my controller is synchronous and eventually return an instance of
WrappedAsyncResult. The WrappedAsyncResult instance is set up to do
nothing on Begin(), except set CompletedSynchronously to true and call
any specified callback. When asyncHandler.EndProcessRequest(ar) is
called we eventually end up in WrappedAsyncResult.End(), where the
controller is finally executed in a blocking manner.

WrappedAsyncResult.AsyncWaitHandle is get {
 return _innerAsyncResult.AsyncWaitHandle;
 }
with innerAsyncResult in this case being a SimpleAsyncResult.

SimpleAsyncResult.AsyncWaitHandle in turn returns null:
    // ASP.NET IAsyncResult objects should never expose a WaitHandle
due to potential deadlocking

    public WaitHandle AsyncWaitHandle {
 get {
 return null;
 }
 }

And this then causes the NullReferenceException in HttpServerUtility.Execute().

Any suggestions to resolve this?

/Oskar


More information about the Mono-devel-list mailing list