Generic object reference error

2
  

System.NullReferenceException: Object reference not set to an instance of an object.

This error is giving in the following code snippet:

Arquivo arquivo = new Arquivo();
ArquivoVersao versao = new ArquivoVersao();
versao.XNOME = "teste";
var list = new List<ArquivoVersao>();
list.Add(versao);
arquivo.ArquivoVersoes = list;
//arquivoVersoes é uma lista de Versoes

Class File:

public class Arquivo
{
    public string ARQUIVO_GUID { get; set; }
    public string XARQUIVO { get; set; }
    public string TAG { get; set; }
    public string EXTENSAO { get; set; }
    public string URL { get; set; }
    public bool IS_STREAM { get; set; }
    public string ULT_ARQUIVO_VERSAO_GUID { get; set; }
    public string TIPO_DE_ARQUIVO_GUID { get; set; }
    public string DIRETORIO_GUID { get; set; }
    public TipoDeArquivo TipoDeArquivo { get; set; }
    public List<ArquivoVersao> ArquivoVersoes { get; set; }
}

Class File Version:

public class ArquivoVersao
{
        public string XNOME { get; set; }
}
    
asked by anonymous 06.02.2015 / 19:48

1 answer

3

Immediately I see a problem using .ToArray() . If you have a variable that is a list and will save in another variable that is also a list of the same type you do not have to convert the list to array .

The code presented in the current version of the question (previously had .ToArray() ) does not contain the declared error:

link

When I have more information I can improve the answer.

You should also consider not using names with all uppercase characters and underline (underlined). This runs out of the default adopted by C # .

    
06.02.2015 / 20:25