.Crystal Report setdatasouce() giving Nullreferenceexception error

Asked

Viewed 42 times

1

Hello.

I am making a simple test report using Crystal Report with c#.

The report is loaded by a . ttx file;

On the controller I put:

 public ActionResult ObterRelatorio()
    {
        try
        {
            byte[] relatorio = new byte[] { };

            Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.pdf","Relatorio"));

            List<QuestaoDTO> lista = QuestaoDTO.ObterRelatorio();
            RelatorioDeQuestao relatorioDeQuestao = new RelatorioDeQuestao();

            relatorio = relatorioDeQuestao.ObterRelatorio(lista);

            return File(relatorio, "application/pdf");
        }
        catch (Exception excecao)
        {
            TempData["MENSAGEM_ERRO"] = excecao.Message;

            return View();
        }
    }

In it I pass a list of objects.

When I load the report gives a Nullreferenceexception error on . Setdatasource(), even though the list is brought in the correct way.

public byte[] ObterRelatorio(IList<QuestaoDTO> listaDoRelatorioDTO)
    {
        try
        {
            Stream fluxoDeDadosDoRelatorio;
            int tamanhoDoFluxoDeDados;
            byte[] vetor;

            Relatorio.SetDataSource(listaDoRelatorioDTO);
            fluxoDeDadosDoRelatorio = Relatorio.ExportToStream(ExportFormatType.PortableDocFormat);
            tamanhoDoFluxoDeDados = Convert.ToInt32(fluxoDeDadosDoRelatorio.Length);
            vetor = new byte[tamanhoDoFluxoDeDados];
            fluxoDeDadosDoRelatorio.Read(vetor, 0, tamanhoDoFluxoDeDados);

            return vetor;
        }
        catch (NullReferenceException ex)
        {
            throw new NullReferenceException(ex.Message);
        }
        catch (Exception excecao)
        {
            throw new Exception(excecao.Message);
        }
    }

What can it be?

Editing, showing how he brings up the list:

inserir a descrição da imagem aqui

  • apparently what is null is the Report (there before Setdatasource), where you are initiating it?

  • Does not bring empty, I edited the post putting an image to show

  • but I don’t mean the list, said that 'Report' there in Report.Setdatasource

  • Sorry for the delay!! So, I saw that the Report object was empty even after it worked... thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.