I am writing an application and I want to keep a list of files selected by the user. Currently, one of my settings is a StringCollection named filesToFetch, which is the user's scope and contains the paths of all the files that the program should extract. I have a button that allows the user to add new files to the list. This is the button click event code
private void button1_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { Properties.Settings.Default.filesToFetch.Add(openFileDialog1.FileName); Properties.Settings.Default.Save(); } }
When I try to add a new file to StringCollection, I get an error
NullReference exception was unhandled
The reference to the object is not installed in the instance of the object.
I think this could happen because filesToFetch was not initialized, but I'm not sure. I could be wrong, but I thought that the object gets a name when it is initialized, and since my settings all get names during development, I assumed that they are automatically initialized when the program starts, but now I think I can be wrong about that. Is this a problem, or am I missing something else?
Here is a screenshot of my settings for reference.

source share