2
papelX.moderador = abc.Id;
papelX.participantes.Add(abc);
I’m finding a NullReferenceException
in that code above.
I’m creating an object papelX
and I will use some properties of the object abc
.
Visual Studio is saying that at the bottom line the object abc
is void.
I don’t understand, because on that first line, as you can see, the property Id
of abc
was duly copied to papelX.moderador
. There was no problem.
Including putting your mouse on top of abc
I realize that several of his properties are duly filled in. It is not null. Why this is happening?
So it must be magic. Or the problem is not quite this one. It has very little information for us to help. If you can put more relevant things in, then you can help. I did not see the exact error, if the line is this same, if there is anything else that might be interfering. It may be that the
participantes
is null and is misinterpreting the error. Even if theabc
is null it is likely that this is no problem, it is possible to add nulls to data collections. I almost put this as an answer, since that’s just what gives p/ respond now.– Maniero
Hi @bigown, thanks for trying to help. It’s my first question here so I don’t know how to write it. O
participantes
is null yes. It is an objectList<Usuario>
, then hopes to receive exactly the kind ofabc
. But it starts with nothing because I just created this objectpapelX
some lines up and I’m populating the fields. Abc would be the first participant in the case. I’m doing something wrong?– Rique Cardoso
Before
papelX.participantes.Add(abc);
try to putpapelX.participantes = new List<Participantes>();
. Note that inList<Participantes>()
, Participants is the Model that will compose the list.– Randrade
Did the answer solve your problem? Do you think you can accept it now? See [tour] to understand how it works. It would be helpful to indicate to everyone that the solution was useful and satisfactory for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero