Error "c # object reference not set as instance of an object"

-1

in my Windows forms application, I have a list of strings saved in User Settings, which is called FileList. The problem is that I see an error, the code is as follows:

private void HomeForm_Load_2(object sender, EventArgs e)
        {
            AlarmPicker.Format = DateTimePickerFormat.Custom;
        AlarmPicker.CustomFormat = "MM/dd/yyyy hh:mm:ss";
        if (Settings.Default.Counter > 0)
        {
            ErrorNoFilesLabel.Visible = false;
        }
        HomeDarkTheme();
        BackWorker.RunWorkerAsync();
    }
private void      backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        if (Settings.Default.FileList.Count > 0)
        {
            foreach (string TheFile in Settings.Default.FileList)
            {
                int I = 8;
                BackWorker.ReportProgress(I);
            }
        }
    }
private void BackWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        if  (Settings.Default.FileList.Count > 0)
        {


            foreach (string TheFile in Settings.Default.FileList)
            {
                Reminders.TaskUC Task = new Reminders.TaskUC();
                Point TP = new Point();
                Task.Name = "Task" + Settings.Default.Counter.ToString();
                TP.Y = 1;
                int Add = 300;
                int Result = Start;
                int Distance = 100;
                Control Last = Controls[Controls.Count - 1];
                TP.X = Last.Location.X + Distance;
                if (Settings.Default.Counter == 1)
                {
                    TP.X = 300;
                }
                Size PanelWidth = new Size();
                PanelWidth.Width = ReminderPanel.Width + 300;
                PanelWidth.Height = ReminderPanel.Height;
                Task.Location = TP;
                this.Controls.Add(Task);
                ReminderPanel.Size = PanelWidth;
                ReminderPanel.Controls.Add(Task);
                XmlSerializer XS = new XmlSerializer(typeof(List<Information>));
                StreamReader Reader = new StreamReader(TheFile);
                Information i;
            }
        }
    }

The problem was previously shown on the line:

foreach (string TheFile in Settings.Default.FileList)

But now I added the line:

if (Settings.Default.FileList.Count > 0)

And now it shows the error there

    
asked by Sergio Marquez 01.07.2018 в 20:41
source

1 answer

0

link

Settings.Default.FileList = new List<string>();

["c # reference to object not set as instance of an object" = > Google Translate = > "C # reference to object not established as instance of an object" = > Google Search = > link ]

    
answered by 01.07.2018 в 23:18