Question

I am all of a sudden getting a "Parameter Not Valid" exception on my production IIS server (Reboot has since cleared the exception). I have a Telerik report that has a PictureBox control which I use to show a users signature. The signature is stored on the SQL Server as varbinary(max). I imported it using this code:

SET EmployeeSignature = (SELECT BulkColumn FROM OPENROWSET(
        Bulk 'C:\Signatures\Justin.bmp', SINGLE_BLOB)AS BLOB)
         EmployeeNumber = '999999'

I am rendering the report as a pdf like so:

 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");

    }

From everything I have read there seems to be a correlation with this particular exception and various flavors of image files, font files, etc. As I stated above, a reboot of the IIS server stopped the ecxception for now but I need to figure out the cause before it happens again. Or find a better way to show the user signature on a report. Any suggestions?

I'm getting the following exception when the report stops working:

ArgumentException: Parameter is not valid.]
   System.Drawing.Image.get_RawFormat() +1624719
   Telerik.Reporting.PictureBox.set_Value(Object value) +145
   LogisticsReports.PoHeader.InitializeComponent() +59097
   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
Was it helpful?

Solution

As the process of creating PDFs can use a lot of memory, you might being seeing an issue which is a manifestation of a memory issue (see here; similar errors occur when generating large bitmaps). What could be happening is that your IIS server is running out of memory for the app pool where your app is running.

From looking at the Telerik documentation I can see that "IReportDocument" implements IDisposable, but your code is not disposing this object.

So I'd first change the code so that ReportDocument has it's memory properly disposed of:

public ActionResult PrintPoReport(string id)
{
 byte[] contents;
 Telerik.Reporting.Processing.RenderingResult result;

 using (var reportDocument = new LogisticsReports.PoHeader())
 {
  var irs = new InstanceReportSource();
  irs.ReportDocument = reportDocument ;
  irs.Parameters.Add(new Parameter("PoID", id));
  var reportProcessor = new  Telerik.Reporting.Processing.ReportProcessor();
  result = reportProcessor.RenderReport("PDF", irs, null);
  contents = result.DocumentBytes;
 }

 return File(contents, "application/pdf", "P0 #" + id + ".pdf");
}

(Note: forgive any errors in this code. I haven't compiled it)

Also run some diagnostics on your IIS server to look for memory issues. Have you checked the IIS logs for issues?

Also are you sure that all of the signature images in your database are valid i.e. not corrupt? See this article which highlights issues which can arise due to invalid images, which sounds a lot like your issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top