The first problem is that you haven't initialized the list, so
rootjson.ListSourcesFile
returns
null
, and any attempt to index into the list throws a
NullReferenceException
.
The second problem is that you haven't added anything to the list. When you try to retrieve the first item of an empty list, you'll get an
ArgumentOutOfRangeException
telling you that the index you're trying to access does not exist.
Try initializing the list before you access it:
RootJson rootjson = new RootJson
{
App = appIdentifier.AppName,
ListSourcesFile = new List<SourcesFile>
{
new SourcesFile
{
Source = "Fdf",
},
},
};
RootJson rootjson = new RootJson();
rootjson.App = appIdentifier.AppName;
rootjson.ListSourcesFile = new List<SourcesFile>();
SourcesFile file = new SourcesFile();
file.Source = "Fdf";
rootjson.ListSourcesFile.Add(file);