Best practice for adding dynamic PictureBox

6 posts, 0 answers
  1. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 04 Oct 2013 Link to this post

    I have a report that has a PictureBox on it which I am using for an employee signature. I store the signature in the SQL server as a varbinary(max). The employee signature will be different for every report and is returned in the SqlDataSource for the report. I recently started getting a ""Parameter Not Valid" exception when rendering the report as a pdf and had to reboot the IIS server to get the report to render again. I must either be doing something wrong or not using the best practice for this scenario.  Here is how I am importing the bmp signature to the table in SQL server:

    UPDATE [HR_Employees]
    SET  EmployeeSignature = (SELECT BulkColumn FROM OPENROWSET(
                Bulk 'C:\Signatures\Justin.bmp', SINGLE_BLOB)AS BLOB)
                WHERE EmployeeNumber = '99999'

    Here is how I am rendering the report to pdf:
    public ActionResult PrintPoReport(string id)
               var irs = new InstanceReportSource();
               irs.ReportDocument = new LogisticsReports.PoHeader();
               irs.Parameters.Add(new Parameter("PoID", id));
               Telerik.Reporting.Processing.ReportProcessor rp = new Telerik.Reporting.Processing.ReportProcessor();
               Telerik.Reporting.Processing.RenderingResult result = rp.RenderReport("PDF", irs, null);
               byte[] contents = result.DocumentBytes;
               return File(contents, "application/pdf", "P0 #" + id + ".pdf");

    I think it is the signature block causing the issue but I could be wrong. Any suggestions as to how to properly add a bmp file to a report dynamically?
  2. Hadib Ahmabi
    Hadib Ahmabi avatar
    181 posts
    Member since:
    Nov 2011

    Posted 09 Oct 2013 Link to this post

    I don't see the code where you dynamically add the picture. 
    First you can try to remove the PictureBox and see if that really is the problem. 
    Additionally, if your pictures are stored locally, then you can pass the full filename using a ReportParameter. 
    You should also be able to see more info about the exception - stack trace, etc.. (you can hook up to the Error event of the ReportProcessor). 
  3. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 09 Oct 2013 Link to this post

    Habid, As I said in my post, the picture is stored in the SQL Server and returned to the report in the SqlDataSource. Depending on the record being returned, a different image will be returned with every report. The report is already in production and I can't remove the picture. It is a picture of a users signature and needs to be on the report. All I can do is wait for it to fail again and reboot the server agian. When I do a search on "Parameter Not Valid" I see a number of posts that seem to indicate it is an issue with retrieving an image from a database like I am doing. Here is a perfect example of a site that addresses the exact exception I am getting
    So lets just say for the sake of argument that loading an image from the database into the report is my issue. What would be a better way to load the image. I could store each users signature locally and name it with users EmployeeID which is part of the report data and dynamically point to the image in the C# code that calls the report and send it a s a parameter. Can you provide a quick code example of how to pass the file name to the report as you had mentioned? How would I then render the image in the report? Thanks for any help.
  4. Stef
    Stef avatar
    3611 posts

    Posted 11 Oct 2013 Link to this post

    Hello Alan,

    The PictureBox.Value property can be set through binding to a field, report parameter, user fucntion or other valid expression from which can be created an image object.

    If you need further help, please send us the exception stack trace, details how you set the image to the PictureBox item, and if the issue is reproducible without the image or with other report. Also specify the used Telerik Reporting version.


    Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

  5. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 22 Oct 2013 Link to this post

    Hi Stef, After properly working for a few days,  the exception is back, here is the Stack Trace:

    [ArgumentException: Parameter is not valid.]
       System.Drawing.Image.get_RawFormat() +1624719
       Telerik.Reporting.PictureBox.set_Value(Object value) +145
       LogisticsReports.PoHeader.InitializeComponent() +59796
       ArctecLogisticsWebFiles.Controllers.LogisticsToolsController.PrintPoReport(String id) +64
       lambda_method(Closure , ControllerBase , Object[] ) +127
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
       System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +129
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +826106
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825328
       System.Web.Mvc.Controller.ExecuteCore() +159
       System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
       System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

    I republished the application after removing the picture box but the exception remains. I'm going to have to re-boot the server to clear the exception. This is a difficult issue to resolve because it works on my development machine, it works on my development IIS server and it works until failure on my production machine. Can you see from this exception what the issue coupld possibly be?
  6. IvanY
    IvanY avatar
    417 posts

    Posted 25 Oct 2013 Link to this post

    Hi Alan,

    In general the error you are getting means that GDI+ cannot create an image from the buffer that is supplied. This issue is usually caused by the image itself, so there is a chance that a particular image (or images) in your database are causing this. Additionally you can check for a similar problem this forum thread - check out rh's answer, you might be facing the same issue.

    Finally in order to help you more adequately we will need some more information and it will be best if you can open a support ticket and send us there a sample project that exhibits the issue. However please note that since most probably the issue is caused by the image itself it will be crucial for us to have that image (stored in a database) otherwise most probably we will not be able to reproduce the issue locally.


    Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Back to Top