private void OpenFileExecute(string fileName) { if (fileName == "") { MessageBox.Show("Enter a name for the file in the text box File Name", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { try { _fileName = fileName; Agents tempAgents = new Agents(); tempAgents.Clear(); //using (var stream = new FileStream(_fileName, FileMode.Open)) using (var stream = new StreamReader(_fileName)) { XmlSerializer XML = new XmlSerializer(typeof(Agents)); tempAgents = (Agents)XML.Deserialize(stream); stream.Close(); } Clear(); foreach (var agent in tempAgents) { Add(agent); } NotifyPropertyChanged("Count"); } catch (Exception e) { MessageBox.Show("There is no file with the given name", "Error", MessageBoxButton.OK, MessageBoxImage.Error); //Console.WriteLine(e); //throw; } } }