0

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
Tommy
  • 39,592
  • 10
  • 90
  • 121
Alan Fisher
  • 2,005
  • 4
  • 41
  • 61

1 Answers1

1

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.

Community
  • 1
  • 1
Ben Smith
  • 19,589
  • 6
  • 65
  • 93
  • Thanks very much for the code example. I did find a simple compile issue and that is 'result' is declared twice. After correcting that I was able to print the report. I'm pretty much only using two users signatures so I don't think it is a corruption issue, I'm leaning towards the memory leak. The only thing that bugs me is that I have a few other reports that render the same way except without the signature block and they have never failed. I'm going to change the code on all reports and see what happens. Question, is the Using statement what is disposing of the memory? – Alan Fisher Oct 22 '13 at 23:01
  • Doh, missed the duplicate definition, I've updated the code. Are these signature blocks large files? I'm guessing not. For all we know the Telerik function could be using a large amount of memory to process a small image. Keep an eye on memory usage. As for the using statement, yes it's a [convenientsyntax for disposing of objects which implement IDisposable](http://msdn.microsoft.com/en-us/library/yh598w02.aspx). As a rule of thumb, any object which uses IDisposable should be encase within a using block (or at least it should be explicitly disposed of). – Ben Smith Oct 22 '13 at 23:10
  • How did you get on with your PDF issue? Did disposing of RenderingResult fix the problem? – Ben Smith Oct 23 '13 at 21:02
  • I changed the code like you showed and had the same exception the next morning. I'm going to try and render the image from a .bmp file rather than SQL and see if that works. I'll keep you posted. Thanks. – Alan Fisher Oct 25 '13 at 00:50
  • I changed the way I am rendering the picturebox. I'm no longer using the SQL field, instead I dynamically point the picturebox Value to a .jpg file that lives on the server. The report caused the exact same issue this morning. Back to square one. I downloaded Redgate's ANTS Memory profiler and will try and see if that gives me any clues. I may also go with a Report Viewer just to narrow things down. Any other suggestions? This report is in production and users are getting angry. Thanks for any help. – Alan Fisher Nov 12 '13 at 20:29
  • Sounds like a nightmare :( I googled for "telerik reportprocessor memory" and could see quite a few issues on the Telerik website regarding memory issues. If you haven't done already, it's probably worth posting a question on their website. They seem to suggest that you should use decent hardware with plenty of memory to generate these reports, are you using a good spec. machine? – Ben Smith Nov 12 '13 at 22:57
  • Did you sort this issue out in the end? Sounded like a nightmare :( Not surprised as a lot of others seemed to have the same problem. – Ben Smith Feb 06 '14 at 16:50
  • 1
    I seemed to have stopped most of the bleeding by providing a link to a jpg image rather than embedding it in the report. I still get an occasional exception but only a couple since doing that. Also from what I gather from Telerik, I should use the new HTML 5 report viewer. I needed to get my solution up to asp.net 4.5 first, which I just finished doing, and will give that a try soon and post results here. – Alan Fisher Feb 06 '14 at 16:54