can't catch error when binding an unsupported byte array

3 posts, 0 answers
  1. Jairo
    Jairo avatar
    5 posts
    Member since:
    Dec 2014

    Posted 05 Jun 2015 Link to this post

    Good day,

    I'm currently migrating some user controls to telerik to use the new features. One of our user controls was a image upload control. Basically it had an asp.net img object and a stardard asp.net file upload object.

    I changed it for a RadBinaryImage and a RadAsyncUpload. So far, the changes have worked. But I encountered a problem. Due to the lack of validation that the old control had, users could upload any file even if it wasn't images (like pdf, .doc, etc). Of course, it was not displayed properly on the asp.img object but it didn't show any exception, just an "x" sign. With the new user control, when I'm navigating through the records in a table and the control encounters one with a byte array that doesn't correspond to an image, it throws the following exception: "ArgumentException: The provided binary data may not be valid image or may contains unknown header".

    I've read several posts in the forum and I already know that this exception is thrown because of the invalid format of the file loaded and that's ok, but I wanted to take control of this error if it happens so I did the following changes in the user control (ascx):

    public void ShowImage(byte[] img)
    {
        try
        {
            String strImageSessionName = String.Format("imagen{0}", imgMuestra.ClientID);
            Session[strImageSessionName] = img;
            imgMain.DataValue = img;
            imgTooltip.DataValue = img;
            imgMuestra.Style["cursor"] = "pointer";
            this.EnableTooltip = true;
        }
        catch (Exception)
        {
            imgMain.ImageUrl = "~/images/image_not_available.jpg";
            imgTooltip.ImageUrl = "~/images/image_not_available.jpg";
            this.EnableTooltip = false;
        }
         
    }
     

     If there's any error when loading the bytes into the control I want to show instead a fixed image. The problem is that the catch block is never reached. It always do the try block entirely even if the data is in an incorrect format. The exception is thrown later in a uncontrolled manner by the form making the form crash.

    What could I do to catch this error if it happens and achieve what I want? Thanks in advance for any help.

  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 10 Jun 2015 Link to this post

    Hello Jairo,

    Could you create a new web site to demonstrate a very basic isolated version of your application? You can open a formal support ticket and send this runnable sample to us so we can debug and analyze the project locally.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jairo
    Jairo avatar
    5 posts
    Member since:
    Dec 2014

    Posted 10 Jun 2015 in reply to Eyup Link to this post

    Hi,

    I've created a support ticket. Thanks

Back to Top