Boletonet | Error generating shipment file

Asked

Viewed 794 times

1

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

The Code below illustrates what I am going through. I fill all variables correctly, but when I will generate the shipment file gives the following exception.

An Exception of type 'System.Exception' occurred in Boleto.Net.dll but was not handled in user code Additional information: Error generating consignment file.

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);

Error happens on last line.

And what I got from additional information is: (However, all my objects were 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 out (if possible) what is causing the problem and also if possible what is the solution.

  • This is one of the (infinite) problems of Boleto.NET. As exceptions generated do not bring relevant information about the error. Just looking at this code will be very difficult to help you. I think the best solution would be to download the sources, manually reference in your project and stampede. It doesn’t sound like a good solution, but it’s better than "shooting in the dark".

2 answers

2

I went through this problem, to solve downloaded the code on official repository and I was debugging to see what was null.

In order for the file to be properly generated, all account data must be filled in correctly. Balcony address must be all filled out too.

In your case is missing the sacado.Endereco.Logradouro and sacado.Endereco.Email. The Logradouro cannot be null.

Some banks have some particularities, you need to read the manual of each and see what are the mandatory information, because in this part the dll fails. You can only know if you debug the code. If you are generating a shipment file to the Cashier bank, you need to have the property set EspecieDocumento and the Remessa.TipoDocumento of 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 this my example the b.Remessa.TipoDocumento = "2" is set as 2 because the bank cashier needs this information to generate the shipment file, being that 1 is for collection without registration and 2 for with registration. Remembering that there is no more billet without registration, so you can leave with 2 same. And the Document Species is Type of document that originated the payment slip (Example: Mercantile Duplicate, Service Duplicate, Promissory Note).

  • Taisbevalle, taking advantage, clarifies me a doubt. The Numerodocumento would be the "nossoNumero"?

  • No, our number is a value that increases with each ticket generated. The document number is a company control number.

  • Interesting link: http://www.jrimum.org/bopepo/wiki/Componente/Documentacao/Negocio#Nosson%C3%Bamero

  • 1

    Thank you! Here my case was exactly that!

2


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

First, with the tips of the companions(as) Jbueno and Taisbevalle, I downloaded the code of Boleto.Net and debugged.

It was necessary to create an instance of the Shipment inside the billet.

boleto.Remessa = new Remessa();

I hope I’ve helped.

Browser other questions tagged

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