简体   繁体   English

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

[英]Castle MonoRail with asynchronous action view render exception

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. 我正在尝试在MonoRail中使用异步操作,但是当呈现视图时,我得到NullReference异常,也使用emtpy视图文件进行测试。

I also tried to call RenderView("uploadTags.vm") in EndUploadTags. 我还尝试在EndUploadTags中调用RenderView(“uploadTags.vm”)。 When I call RenderText(s) in EndUploadTags I don't get the exception. 当我在EndUploadTags中调用RenderText时,我没有得到异常。

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

This is a bug in old versions of MonoRail. 这是旧版MonoRail中的一个错误。 It works in MonoRail 2.1 RC , but not in an old version I just tried, I got the same null ref exception. 它适用于MonoRail 2.1 RC ,但不是我刚试过的旧版本,我得到了相同的null ref异常。

This is what revision 5688 looked like in Subversion, which is where the NullReferenceException is coming from. 这是修订5688在Subversion中的样子,这是NullReferenceException的来源。 The code no longer uses the HttpContext for the cache. 代码不再使用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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM