5
Time or other the execution of my systems are interrupted by this error, when it happens, a if(atributo != null)
It usually does, but it pollutes the code, "Oh, but this variable needs to have a value right?" the problem happens just when I will assign a value while filling the attributes of an object, this error appears.
"An Exception of type 'System.Nullreferenceexception' occurred in Nomedoprojeto.dll but was not handled in user code"*
I have an associative class that keeps Permissoes
of a page and the user who has this permission, while trying to fill in the associative (FluxoUsuario
) he points out the error:
Follows part of FluxosController.cs
:
for (int i = 0; i < vwfluxo.Usuarios.Count(); i++)
{
if (Request.Params["cb" + i] != null)
{
FluxoUsuario fu = new FluxoUsuario();
var a = bool.Parse(Request.Form["cb" + i].Split(',')[0]);
var b = Request.Params["rb" + i]; //Pega valor do radioButton
if (a)//Verifica se a checkBox está marcada
{
if(db.FluxoUsuario.ToList().Where(x => x.Usuario.Equals(vwfluxo.Usuarios[i])).Count() > 0 == true)
{
}
fu.Fluxo.FluxoID = fluxo.FluxoID; //O Erro acontece nessa linha.
//fu.Fluxo é do tipo Fluxo, FluxoID é int. fu.Fluxo.FluxoID realmente precisa estar null quando acontece o erro, afinal, está sendo atribuido um valor para ele nesse momento.
fu.Usuario.IDUser = vwfluxo.Usuarios[i].IDUser;
fu.Fluxo = fluxo;
fu.Usuario = vwfluxo.Usuarios[i];
if (b == "ler")
fu.TipoPermissao = TipoPermissao.Ler;
else
fu.TipoPermissao = TipoPermissao.LerEscrever;
if (!fluxo.UsuariosPermitidos.Contains(fu))
{
fluxo.UsuariosPermitidos.Add(fu);
}
}
}
}
If you are trying to define the value of an object property, for example
Objeto.Nome
, and the object is null this error occurs. If you post the exact snippet where the error occurs, I can help more.– Richard Dias