具有异步操作视图的Castle MonoRail呈现异常

时间:2012-10-30 11:53:45

标签: exception asynchronous action castle-monorail nvelocity

我正在尝试在MonoRail中使用异步操作,但是当呈现视图时,我得到一个NullReference异常,也使用emtpy视图文件进行测试。

我还尝试在EndUploadTags中调用RenderView(“uploadTags.vm”)。 当我在EndUploadTags中调用RenderText时,我没有得到异常。

堆栈跟踪:

   [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

这是我的测试代码:

        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;
        }

1 个答案:

答案 0 :(得分:2)

这是旧版MonoRail中的一个错误。它适用于MonoRail 2.1 RC,但不是我刚试过的旧版本,我得到了相同的空引用异常。

这是修订5688在Subversion中的样子,这是NullReferenceException的来源。 code不再使用HttpContext作为缓存。

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;
}