Null Exception With Overridden AsyncUploadHandler

3 posts, 0 answers
  1. stuart
    stuart avatar
    8 posts
    Member since:
    Oct 2012

    Posted 06 Mar 2013 Link to this post

    I've implemented a custom handler, however, I get a null exception further down the stack which I can't step through. I'm wondering if I'm doing something wrong or if there is a bug in the handler. It seems to happen after the file upload is successful.

    • I've set HttpHandlerUrl on RadAsynUpload to "~/EDocsAsyncUpload" 
    • I've added the handler in the .config: <add name="EDSExtendedRadAsyncUploader" verb="*" path="EDocsAsyncUpload" type="EDS.DNN.ExtendedAsyncUploadHandler.ExtendedAsyncUploadHandler, EDS.DNN.ExtendedAsyncUploadHandler"/>
    • All permissions are set for the app pool user on the temp folder. I've allow all users access to the handler with this config: <location path="EDocsAsyncUpload"><system.web><authorization><allow users="*"/></authorization></system.web></location>
    • Telerik.Web.UI version is 2012.1.411.35
    • I'm using Windows 7. All browsers regardless of which plugin I use exhibit the same behaviour.

        [Serializable]
        public class ExtendedAsyncUploadResult : IAsyncUploadResult
        {
            public string TempFileName { get; set; }
            public bool Valid { get; set; }
            public string ValidationMessage { get; set; }
            public int ContentLength { get; set; }
            public string ContentType { get; set; }
            public string FileName { get; set; }
            public int Pages { get; set; }
            public ExtendedAsyncUploadResult()
            {
                this.TempFileName = string.Empty;
                this.ValidationMessage = string.Empty;
                this.ContentType = string.Empty;
                this.FileName = string.Empty;
            }
        }
     
    public class ExtendedAsyncUploadHandler : Telerik.Web.UI.AsyncUploadHandler
        {
            protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context,
                IAsyncUploadConfiguration configuration, string tempFileName)
            {
                IAsyncUploadResult result = base.Process(file, context, configuration, tempFileName);
                ExtendedAsyncUploadResult extendedResult = base.CreateDefaultUploadResult<ExtendedAsyncUploadResult>(file);
                extendedResult.TempFileName = tempFileName;
                 
                try
                {
                    string imagePath = Path.Combine(configuration.TempTargetFolder, tempFileName);
                    if (File.Exists(imagePath))
                    {
                        ImagingService.ImagingServiceClient client
                            = new ImagingService.ImagingServiceClient("NetTcpBinding_IImagingService");
     
                        ImageServiceValidationResult validationResult = client.ValidateImage(
                            imagePath, Path.GetExtension(result.FileName));
     
                        extendedResult.Valid = validationResult.State
                            == ImageServiceValidationResult.ValidState.Valid;
     
                        extendedResult.ValidationMessage = validationResult.Errors.ToString();
                        extendedResult.Pages = validationResult.PageCount;
                    }
                    else
                    {
                        throw new Exception("File does not exist.");
                    }
     
                }
                catch (Exception ex)
                {
                    extendedResult.ValidationMessage = ex.Message;
                    extendedResult.Valid = false;
                }
     
                return extendedResult;
            }
     
        }


    I get the following exception.

    <!-- 
    [NullReferenceException]: Object reference not set to an instance of an object.
       at System.Web.Util.StringUtil.memcpyimpl(Byte* src, Byte* dest, Int32 len)
       at System.Web.Util.StringUtil.UnsafeStringCopy(String src, Int32 srcIndex, Char[] dest, Int32 destIndex, Int32 len)
       at System.Web.HttpWriter.Write(String s)
       at Telerik.Web.UI.AsyncUpload.ResponseWriter.WriteToResponse(String response)
       at Telerik.Web.UI.AsyncUploadHandler.ProcessUploadedFile()
       at Telerik.Web.UI.AsyncUploadHandler.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    --> 
    Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=ScriptManager_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d4.0.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aen-US%3ac9cbdec3-c810-4e87-846c-fb25a7c08002%3aea597d4b%3ab25378d2%3bTelerik.Web.UI%2c+Version%3d2012.1.411.35%2c+Culture%3dneutral%2c+PublicKeyToken%3d121fae78165ba3d4%3aen-US%3af1f77841-f126-4726-9fc2-0ee8be7d2341%3a16e4e7cd%3af7645509%3a24ee1bba%3af46195d3%3a2003d0b8%3a1e771326%3aaa288e2d%3aed16cbdc%3a874f8ea2%3ac172ae1e%3a19620875%3a9cdfc6e7%3ae330518b%3ac8618e41%3ae4f8f289%3a490a9d4e%3abd8f85e4%3a68f76a79%3a2a2fc429%3a7165f74%3ab7778d6c%3a52af31a4, line 13675 character 8

  2. stuart
    stuart avatar
    8 posts
    Member since:
    Oct 2012

    Posted 06 Mar 2013 Link to this post

    Several observations:
    • When I step through AsyncUploadHandler, I don't see the error, however, when I detach the debugger and clear all breakpoints, I get the error. My breakpoint as set on ProcessRequest.
    • I can go to http://localhost/EDocsAsyncUpload just fine on the first attempt, however, all subsequent attempts yield the same error.
    • Removing the custom handler resolves the error. However, I need to implement a custom handler in order to return custom image validation data back to the client. Is there an alternative way to do this without requiring a custom handler?

    It's not the code in my custom handler, because I get the same outcome with the following code:
    public class ExtendedAsyncUploadHandler : Telerik.Web.UI.AsyncUploadHandler
    {
        protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context,
            IAsyncUploadConfiguration configuration, string tempFileName)
        {
            return base.Process(file, context, configuration, tempFileName);
        }
    }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 08 Mar 2013 Link to this post

    Hello Stuart,

    Straight to the point. The issue origins from our handler's implementation. We used to set IsReusable property to true which causes the problem. In the latest version of our controls that problem is fixed.
    Here is the good part. The problem could be easily resolved in the previous versions of the RadAsyncUpload. E.g.:
    namespace MyCustomCode
    {
        public class CustomHandler : Telerik.Web.UI.AsyncUploadHandler, IHttpHandler
        {
            protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
            {
                return base.Process(file, context, configuration, tempFileName);
            }
     
            bool IHttpHandler.IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
     
    Also I am sending you a sample which demonstrates that implementation. Please review the attachment.

    Kind regards,
    Peter Filipov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top