R – Exception on dowloading Pdf file in ASP.NET

asp.netcrystal-reportspdf

I am downloading a Pdf file created by crystal report and I download as

 ReportDocument repDoc = ( ReportDocument ) System.Web.HttpContext.Current.Session["StudyReportCrystalDocument"];
        // Stop buffering the response
        Response.Buffer = false;
        // Clear the response content and headers
        Response.ClearContent();
        Response.ClearHeaders();
        try
        {    
            repDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "StudyReport" );
        }
        catch( Exception ex )
        {
        }

Eventhough it is working But I got an exception

base {System.SystemException} = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

Can anyone explain what is the reason for this and how to override the exception?

Best Answer

Try this