BoletoNet | Error generating shipping file

1

Hello, I need help with this problem. It is from Boleto.NET and as I saw that the community here has a lot of knowledge about it, I decided to post it.

The following chart illustrates what I'm going through. I fill in all the variables correctly, but when I generate the delivery file it gives the following exception.

  

An exception of type 'System.Exception' occurred in Boleto.Net.dll but was not handled in user code.

Code:

        BoletoNet.Boleto boleto = new BoletoNet.Boleto();

        #region SACADO
        Sacado sacado = new Sacado();
        sacado.Nome = "";
        sacado.CPFCNPJ = "";
        sacado.Endereco = new Endereco();
        sacado.Endereco.End = "";
        sacado.Endereco.Bairro = "";
        sacado.Endereco.Cidade = "";
        sacado.Endereco.CEP = "";
        sacado.Endereco.UF = "";
        #endregion

        #region CEDENTE
        Cedente cedente = new Cedente();
        cedente.Nome = "";
        cedente.CPFCNPJ = "";
        cedente.MostrarCNPJnoBoleto = true;
        cedente.Carteira = "16";
        cedente.Endereco = new Endereco();
        cedente.Endereco.End = "";
        cedente.Endereco.Bairro = "";
        cedente.Endereco.Cidade = "";
        cedente.Endereco.CEP = "";
        cedente.Endereco.UF = "";
        cedente.ContaBancaria = new ContaBancaria();
        cedente.ContaBancaria.Agencia = "";;
        cedente.ContaBancaria.Conta = "";
        cedente.Codigo = "";
        #endregion


        // Banco do Brasil
        Instrucao_BancoBrasil instrucao = new Instrucao_BancoBrasil();
        instrucao.Descricao = boletobd.observacaoBoleto.ToString(); 
        boleto.Instrucoes.Add(instrucao);

        EspecieDocumento_BancoBrasil especie = new EspecieDocumento_BancoBrasil("16");
        boleto.EspecieDocumento = especie;


        boleto.DataVencimento = Datetime.Now;
        boleto.DataDocumento = Datetime.Now;
        boleto.ValorBoleto = 50;
        boleto.Carteira = 16
        boleto.NossoNumero = 1000;
        boleto.Sacado = sacado;
        boleto.Cedente = cedente;
        boleto.ModalidadeCobranca = Convert.ToInt16(16);

        boleto.PercMulta = 10;
        boleto.JurosMora = 5;

        #region BOLETO BANCARIO
        BoletoBancario boleto_bancario = new BoletoBancario();
        boleto_bancario.CodigoBanco = 001;
        boleto_bancario.Boleto = boleto;
        boleto_bancario.MostrarCodigoCarteira = false;
        boleto_bancario.MostrarComprovanteEntrega = true;
        boleto_bancario.GerarArquivoRemessa = true;
        boleto_bancario.Boleto.Valida();
        #endregion


        Boletos objBOLETOS = new Boletos();
        objBOLETOS.Add(boleto);


        var memoryStr = new MemoryStream();
        var objREMESSA = new ArquivoRemessa(TipoArquivo.CNAB400);
        objREMESSA.GerarArquivoRemessa("09", new Banco(001), cedente, objBOLETOS, memoryStr, 1000);

The error happens on the last line.

And what I got from additional information is: (But all my objects have been set.)

  

System.NullReferenceException: Object reference not set to an instance   of an object.

For the question not to be so specific to Boleto.NET, I would like to know how to find (if possible) what is causing the problem and also if possible what the solution.

    
asked by anonymous 11.01.2017 / 15:16

2 answers

2

To register here and help the community, I will describe what I did to resolve.

First of all, with the tips of Jbueno and Taisbevalle, I downloaded the Boleto.Net code and debugged.

It was necessary to create an instance of the Shipment within the ticket.

boleto.Remessa = new Remessa();

I hope I have helped.

    
11.01.2017 / 18:10
2

I went through this problem, so I downloaded the code in the official repository and I was debugging to see what was missing.

/ p>

In order for the file to be generated correctly, all account data must be filled in correctly. The address of the sacado must be completed as well.

In your case the sacado.Endereco.Logradouro and sacado.Endereco.Email are missing. Logradouro can not be null.

Some banks have some peculiarities, you need to read the manual of each one and see what information is required, because in this part the dll fails. You can only know if you debug the code. If you are generating a delivery file for the Cash Bank, you need to set the EspecieDocumento and Remessa.TipoDocumento property to Boleto .

Boleto b = new Boleto(item.VencimentoDate, item.ValorDec, item.CarteiraStr, item.NossoNumeroStr, cedente);
    b.NumeroDocumento = item.NumeroDocumentoStr.Completa('0', 10);
    b.EspecieDocumento = new EspecieDocumento(conta.IdBanco.CodigoStr.ToInt32()); // Caixa precisa
    b.EspecieDocumento.Codigo = "01";
    b.Remessa = new Remessa();
    b.Remessa.TipoDocumento = "2";

In my example, the b.Remessa.TipoDocumento = "2" is set to 2 because the cash bank needs this information to generate the delivery file, 1 is for collection without registration and 2 for registration. Remember that there is no more ticket without registration, so you can leave with 2 same. And the Type of Document is Type of document that originated the payment slip (Example: Business Duplicate, Duplicate of Service Provision, Promissory Note).

    
11.01.2017 / 17:27