Question : Exporting to pdf from crystal reports stopped working

I have a piece of code that was working fine and is all of a sudden throwing the following error

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

on this line -- rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, context.Response, false, string.Empty);

rd is a ReportDocument.

this code was working fine. I do not know why it is throwing this error now! please help I need this solved!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
public void ProcessRequest(HttpContext context)
    {
        ReportDocument rd = new ReportDocument();
        try
        {
            string path = context.Server.MapPath(ResolveUrl(GetReportPath()));
            rd.Load(path);
 
            if (GetIsODBC() == true)
            {
                string user = System.Configuration.ConfigurationManager.AppSettings["ReportUserName"];
                string password = System.Configuration.ConfigurationManager.AppSettings["ReportUserPassword"];
                rd.SetDatabaseLogon(user, password);
            }
            this.SetReportDataSources(context, rd); //set the data sources
 
            context.Response.Clear();
            rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, context.Response, false, string.Empty);
 
            context.Response.ContentType = "application/pdf";
            context.Response.Flush();
            context.Response.Close();
        }
        catch (Exception e)
        {
            context.Response.Clear();
            context.Response.Write(e.ToString());
            context.Response.Flush();
            context.Response.Close();
        }
        finally
        {
            rd.Close();
        }
    }

Answer : Exporting to pdf from crystal reports stopped working

it wasn't specifically the catch that was breaking it was the code inside the catch, crystal must have been messing with the Responce within its code (being a black box to me I don't really know what they are doing), and this must have been in conflict with my attempt to write to the reponce, because the below code on its own should not have caused me an issue
1:
2:
3:
4:
     context.Response.Clear();
     context.Response.Write(e.ToString());
     context.Response.Flush();
     context.Response.Close();
Random Solutions  
 
programming4us programming4us