Cannot evaluate Expression because the Current thread is in a stack overflow state

Asked

Viewed 1,163 times

3

You’re making that mistake:

Cannot evaluate Expression because the Current thread is in a stack overflow state

in the variable qtde adding it to the list desci.

class descricaoo : IInstrucao
    {
        private string descricaobol;
        public descricaoo(int ibanco, int codigo, string descricaobol, int qtde)
        {
            this.descricaobol = descricaobol;
            List<IInstrucao> desci = new List<IInstrucao>();
            desci.Add(new descricaoo(ibanco, codigo, descricaobol, qtde));
        }
        public IBanco Banco { get; set; }
        public int Codigo { get; set; }
        public string Descricao { get; set; }
        public int QuantidadeDias { get; set; }
    }

1 answer

3


Pay attention to what you are doing. Enter the builder descricaoo, within it you create a list and add an item in it. This item is created by calling a new object of the same class. That is, it will call this constructor again. What happens when you call it? It will call this constructor once more. And so it goes indefinitely. Until the memory reserved to allocate local variables no more room and burst.

Your logic is very wrong. Rethink the problem and see how you have to create this class. I can’t help much without knowing the problem, but you can see that there are several problems, not only in the builder, but in the whole class. Maybe in the whole application.

  • Now I made an if :"if (went down!=null)", as I quit the class if the list went down is not null?

  • This is not the only way to help. Ask a question detailing what you did, what the problem is and what should happen. But I’m telling you, you don’t leave class.

  • I’m making a system to issue billets. This information needs to be passed to the Iinstrucao interface and then passed to the html variables to send the boleto. It has a function that takes the data from the database, and from this function I send the information by parameter to the descricaoo class, and this data will be added in a list of type Iinstrucao and thus be passed to the variables of the boleto.

Browser other questions tagged

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