0

I'm trying to use async actions in MonoRail but when the view is rendered I get an NullReference exception, also tested with emtpy view file.

I also tried to call RenderView("uploadTags.vm") in EndUploadTags. When I call RenderText(s) in EndUploadTags I don't get the exception.

Stacktrace:

   [NullReferenceException: Object reference not set to an instance of an object.]
   Castle.MonoRail.Framework.Services.DefaultCacheProvider.Get(String key) +163
   Castle.MonoRail.Framework.Views.NVelocity.CustomResourceManager.GetResource(String resourceName, ResourceType resourceType, String encoding) +68
   NVelocity.Runtime.RuntimeInstance.GetTemplate(String name, String encoding) +57
   NVelocity.Runtime.RuntimeInstance.GetTemplate(String name) +82
   NVelocity.App.VelocityEngine.GetTemplate(String name) +47
   Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine.Process(String viewName, TextWriter output, IEngineContext context, IController controller, IControllerContext controllerContext) +564
   Castle.MonoRail.Framework.Services.DefaultViewEngineManager.Process(String templateName, TextWriter output, IEngineContext context, IController controller, IControllerContext controllerContext) +237
   Castle.MonoRail.Framework.Controller.ProcessView() +146
   Castle.MonoRail.Framework.Controller.EndProcess() +1579
   Castle.MonoRail.Framework.BaseAsyncHttpHandler.EndProcessRequest(IAsyncResult result) +141

[MonoRailException: Error processing MonoRail request. Action uploadtags on asyncController vendor]
   Castle.MonoRail.Framework.BaseAsyncHttpHandler.EndProcessRequest(IAsyncResult result) +461
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +86

This is my test code:

        private Output output;
        public delegate string Output();

        private string DoNothing()
        {
            return "nothing";
        }

        private string Upload()
        {
            return "upload";
        }

        public IAsyncResult BeginUploadTags(HttpPostedFile xmlFile, Boolean doUpload)
        {
            if (IsPost)
            {
                output = Upload;
                return output.BeginInvoke(ControllerContext.Async.Callback, null);
            }
            output = DoNothing;
            return output.BeginInvoke(ControllerContext.Async.Callback, null);
        }

        public void EndUploadTags()
        {
            var s = output.EndInvoke(ControllerContext.Async.Result);
            PropertyBag["logging"] = s;
        }
ZxCvBnM
  • 277
  • 3
  • 14

1 Answers1

2

This is a bug in old versions of MonoRail. It works in MonoRail 2.1 RC, but not in an old version I just tried, I got the same null ref exception.

This is what revision 5688 looked like in Subversion, which is where the NullReferenceException is coming from. The code no longer uses the HttpContext for the cache.

public object Get(String key)
{
    if (logger.IsDebugEnabled)
    {
        logger.DebugFormat("Getting entry with key {0}", key);
    }

    return GetCurrentContext().Cache.Get(key);
}

private static HttpContext GetCurrentContext()
{
    return HttpContext.Current;
}
Jonathon Rossi
  • 4,149
  • 1
  • 22
  • 32
  • This is not a real anwser to the question. You only ask for more details, please use comment for such demand – greydet Oct 30 '12 at 13:17
  • Sorry, I tried but I can't find how to do that. Maybe I'm limited by my low rep? Yes, I don't have 50 rep (http://meta.stackexchange.com/questions/117496/missing-add-comment-link-button). – Jonathon Rossi Oct 30 '12 at 13:22
  • Logging is configured like this: container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Log4net, "log4net.config")); – ZxCvBnM Oct 30 '12 at 15:16
  • Please see my updated answer, this has nothing to do with logging but the version of MonoRail which had a defect with async actions. – Jonathon Rossi Oct 31 '12 at 08:56