Note that there are some explanatory texts on larger screens.

plurals
  1. POXmlSerializer crashing only when "Start without debugging", but not "Step Into"
    primarykey
    data
    text
    <p>So as the title says, I'm having an issue with XmlSerializer. If I run "Step Into" it runs fine, and saves as it should. But if I "Start without debugging" it runs until the line </p> <pre><code>XmlSerializer serial = new XmlSerializer(typeof(ObservableCollection&lt;Bill&gt;)); </code></pre> <p>at which point it crashes. I've tried putting a thread.sleep beforehand to make sure it's clear, but no help. I've been searching here and google all day...Please help me figure out the problem??? </p> <p>Here is the full code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.Win32; using System.IO; using System.Data; using System.Xml.Serialization; using System.Collections.ObjectModel; namespace BudgetHelper { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public Bills billsClass = new Bills(); public MainWindow() { InitializeComponent(); upcomingDueBills.ItemsSource = billsClass.PopulateUpcomingBills(); } public void RefreshBills() { upcomingDueBills.Items.Refresh(); } private void addBill_Click(object sender, RoutedEventArgs e) { AddAccount addAccountWindow = new AddAccount(); addAccountWindow.ShowDialog(); RefreshBills(); } private void exitMenu_Click(object sender, RoutedEventArgs e) { this.Close(); } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { MessageBoxResult key = MessageBox.Show( "Are you sure you want to quit", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); e.Cancel = (key == MessageBoxResult.No); } private void openMenu_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.DefaultExt = ".txt"; openDialog.FileName = "Text Documents (.txt)"; Nullable&lt;bool&gt; result = openDialog.ShowDialog(); if (result == true) { string filename = openDialog.FileName; } } private void updateBills_Click(object sender, RoutedEventArgs e) { upcomingDueBills.Items.Refresh(); } private void saveMenu_Click(object sender, RoutedEventArgs e) { if (upcomingDueBills == null) { return; } else { billsClass.SaveBills(); } } } } using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.ComponentModel; using System.Collections.ObjectModel; using System.Xml.Serialization; using Microsoft.Win32; using System.Threading; namespace BudgetHelper { public class Bills : IEditableObject { ObservableCollection&lt;Bill&gt; billCollection = new ObservableCollection&lt;Bill&gt;(); public ObservableCollection&lt;Bill&gt; PopulateUpcomingBills() { using (StreamReader reader = new StreamReader(@"c:\users\Keven\Documents \Test.txt")) { while (!reader.EndOfStream) { string line = reader.ReadLine(); string[] fields = line.Split(new char[] { '|' }); billCollection.Add(new Bill() { accountName = fields[0], projectedDueDate = DateTime.Parse(fields[1]), projectedAmount = decimal.Parse(fields[2]), totalDue = decimal.Parse(fields[3]), category = fields[4], notes = fields[5], paidStatus = bool.Parse(fields[6]) }); } } return billCollection; } public void AddNewBill(string account, DateTime dueDate, decimal amount, decimal total, string category, string notes, bool isPaid) { billCollection.Add(new Bill() { accountName = account, projectedDueDate = dueDate, projectedAmount = amount, totalDue = total, category = category, notes = notes, paidStatus = isPaid }); } public void SaveBills() { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.AddExtension = true; saveDialog.DefaultExt = ".xml"; saveDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; saveDialog.InitialDirectory = @"C:\Users\Keven\Documents"; saveDialog.OverwritePrompt = true; saveDialog.Title = "New Account Details"; saveDialog.ValidateNames = true; if (saveDialog.ShowDialog().Value) { Thread.Sleep(2000); MessageBox.Show("2"); XmlSerializer serial = new XmlSerializer(typeof (ObservableCollection&lt;Bill&gt;)); using (StreamWriter writer = new StreamWriter(saveDialog.FileName)) { serial.Serialize(writer, billCollection); } } } public static MainWindow main; public object UpcomingDueBills { get; set; } public class Bill { public string accountName { get; set; } public DateTime projectedDueDate { get; set; } public decimal projectedAmount { get; set; } public decimal totalDue { get; set; } public string category { get; set; } public string notes { get; set; } public bool paidStatus { get; set; } } void IEditableObject.BeginEdit() { throw new NotImplementedException(); } void IEditableObject.CancelEdit() { throw new NotImplementedException(); } void IEditableObject.EndEdit() { throw new NotImplementedException(); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.IO; using Microsoft.Win32; using System.Windows.Threading; using System.Threading; using System.Data; namespace BudgetHelper { /// &lt;summary&gt; /// Interaction logic for AddAccount.xaml /// &lt;/summary&gt; public partial class AddAccount : Window { public Bills bills = new Bills(); public AddAccount() { InitializeComponent(); } private void cancel_Click(object sender, RoutedEventArgs e) { this.Close(); } private void saveAccountInfo_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.AddExtension = true; saveDialog.DefaultExt = "txt"; saveDialog.InitialDirectory = @"C:\Users\Keven\Documents"; saveDialog.OverwritePrompt = true; saveDialog.Title = "New Account Details"; saveDialog.ValidateNames = true; if (saveDialog.ShowDialog().Value) { } this.Close(); } private void done_Click(object sender, RoutedEventArgs e) { bills.AddNewBill(newAccountName.Text, projectedDueDate.SelectedDate.Value, decimal.Parse(projectedAmount.Text.ToString()), decimal.Parse(totalDue.Text.ToString()), accountCategory.Text, accountNotes.Text, (bool)isPaid.IsChecked); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload