title: Error trying to download Crystal Report PDF
body: <p>I'm trying to implement Crystal Reports to my project</p>
  
  <p>My Home Controller:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data.Entity;
  using System.IO;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using Biblioteca.Models;
  using CrystalDecisions.CrystalReports.Engine;
  
  namespace Biblioteca.Controllers
  {
      public class HomeController : Controller
      {
          private BibliotecaDatabase db = new BibliotecaDatabase();
  
          public ActionResult Index()
          {
              var totalesviewmodel = new TotalesViewModel();
              totalesviewmodel.MontoCopias = db.AlumnosList.Sum(o =&gt; o.Copias);
              totalesviewmodel.MontoImpresiones = db.AlumnosList.Sum(o =&gt; o.Impresiones);
              totalesviewmodel.DineroDeposito = db.AlumnosList.Sum(o =&gt; o.Deposito);
              totalesviewmodel.DineroSap = db.AlumnosList.Sum(o =&gt; o.Sap);
              totalesviewmodel.MontoCopiasMaestro = db.MaestrosList.Sum(o =&gt; o.Copias);
              totalesviewmodel.MontoImpresionesMaestro = db.MaestrosList.Sum(o =&gt; o.Impresiones);
              return View(totalesviewmodel);
          }
  
          public ActionResult Reports()
          {
              List&lt;Alumno&gt; allDatos = new List&lt;Alumno&gt;();
              using (BibliotecaEntities dc = new BibliotecaEntities())
              {
                  allDatos = dc.Alumnos.ToList();
              }
              return View(allDatos);
          }
  
          public ActionResult ExportReport()
          {
              List&lt;Alumno&gt; allDatos = new List&lt;Alumno&gt;();
              using (BibliotecaEntities dc = new BibliotecaEntities())
              {
                  allDatos = dc.Alumnos.ToList();
              }
  
              ReportDocument rd = new ReportDocument();
              rd.Load(Path.Combine(Server.MapPath("~/Reports"), "rpt_datos.rpt"));
              rd.SetDataSource(allDatos);
  
              Response.Buffer = false;
              Response.ClearContent();
              Response.ClearHeaders();
  
              try
              {
                  Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                  stream.Seek(0, SeekOrigin.Begin);
                  return File(stream, "application/pdf", "DatoList.pdf");
              }
              catch (Exception ex)
              {
                  throw;
              }
          }
  
          public ActionResult Contact ()
          {
              ViewBag.Message = "Your contact page.";
  
              return View();
          }
      }
  }
  </code></pre>
  
  <p>When I try to download a PDF file of my report, my project stops at:</p>
  
  <pre><code>rd.SetDataSource(allDatos);
  </code></pre>
  
  <p>With this error:</p>
  
  <blockquote>
    <p>An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll but was not handled in user code</p>
  </blockquote>
  
  <p>When I click continue my browser says:</p>
  
  <blockquote>
    <p>The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>