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".
– Jéf Bueno