user3617652
user3617652

Reputation: 143

KeyValuePair<double,double> and a List of these

I've got to display a chart with 4 series in it. I was able to make this work with my data. However, it gives a parse error (see below) when I start updating my lists of data. I.E it gives me an error before even trying to "update" the chart. Heck, I've even remove the chart from the equation and I still get the same parsing error.

Here's how my lists are declared:

public partial class MainWindow : Window
    {
List<KeyValuePair<double, double>> channel1List = new List<KeyValuePair<double, double>>();
        List<KeyValuePair<double, double>> channel2List = new List<KeyValuePair<double, double>>();
        List<KeyValuePair<double, double>> channel3List = new List<KeyValuePair<double, double>>();
        List<KeyValuePair<double, double>> channel4List = new List<KeyValuePair<double, double>>();
        List<List<KeyValuePair<double, double>>> rampsList = new List<List<KeyValuePair<double, double>>>();

In my main, I've got:

 // DEFAULT CHANNEL 1 LIST
            channel1List.Add(new KeyValuePair<double, double>(0, 0));
            channel1List.Add(new KeyValuePair<double, double>(DMIN1, 0));
            channel1List.Add(new KeyValuePair<double, double>(DMAX1, 100));
            channel1List.Add(new KeyValuePair<double, double>(30, 100));
            // DEFAULT CHANNEL 2 LIST
            channel2List.Add(new KeyValuePair<double, double>(0, 0));
            channel2List.Add(new KeyValuePair<double, double>(DMIN2, 0));
            channel2List.Add(new KeyValuePair<double, double>(DMAX2, 100));
            channel2List.Add(new KeyValuePair<double, double>(30, 100));
            // DEFAULT CHANNEL 3 LIST
            channel3List.Add(new KeyValuePair<double, double>(0, 0));
            channel3List.Add(new KeyValuePair<double, double>(DMIN3, 0));
            channel3List.Add(new KeyValuePair<double, double>(DMAX3, 100));
            channel3List.Add(new KeyValuePair<double, double>(30, 100));
            // DEFAULT CHANNEL 4 LIST
            channel4List.Add(new KeyValuePair<double, double>(0, 0));
            channel4List.Add(new KeyValuePair<double, double>(DMIN4, 0));
            channel4List.Add(new KeyValuePair<double, double>(DMAX4, 100));
            channel4List.Add(new KeyValuePair<double, double>(30, 100));


            channel1List.RemoveAt(1);
            channel1List.Insert(1, new KeyValuePair<double, double>(DMIN1, 0));


            // DEFAULT LIST OF RAMPS
            rampsList.Add(channel1List);
            rampsList.Add(channel2List);
            rampsList.Add(channel3List);
            rampsList.Add(channel4List);
            // DRAW DEFAULT CHART
            rampsChart.DataContext = rampsList;

noticed the 2 lines "channel1.RemoveAt(1)..../..." these were just to test, that I am able to remove an entry and replace it with a new one. These series are only 4 points each, and I always need to update only item 1 and 2. 0 and 3 are never updated.

Anyway, this code above works fine. It plots the charts. no parsing error.

Now, like I said I need to udpate this chart when the user is moving a slider. I've got a ValueChanged event set for this slider, which works fine for updating a couple of labels.

But if I had the SAME 2 lines:

channel1List.RemoveAt(1);
channel1List.Insert(1, new KeyValuePair<double, double>(DMIN1, 0));

then it gives me no error when building the project but gives me this error when I hit Start...

An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

I have no clue why it's doing this.

any idea? thanks Steve

edit: complete stack:

'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'Z:\Temperature Controller\Software\C#\SWFT Imperium (WPF)\SWFT Imperium\SWFT Imperium\bin\Debug\SWFT Imperium.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x2d84 has exited with code 259 (0x103).
The thread 0x2ae0 has exited with code 259 (0x103).
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'Z:\Temperature Controller\Software\C#\SWFT Imperium (WPF)\SWFT Imperium\SWFT Imperium\bin\Debug\SWFT Imperium.exe'. Symbols loaded.
Step into: Stepping over non-user code 'SWFT_Imperium.App..ctor'
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Step into: Stepping over non-user code 'SWFT_Imperium.App.Main'
Step into: Stepping over non-user code 'SWFT_Imperium.App.InitializeComponent'
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'Z:\Temperature Controller\Software\C#\SWFT Imperium (WPF)\SWFT Imperium\SWFT Imperium\bin\Debug\System.Windows.Controls.DataVisualization.Toolkit.dll'. Symbols loaded.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationUI\v4.0_4.0.0.0__31bf3856ad364e35\PresentationUI.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'The invocation of the constructor on type 'SWFT_Imperium.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'.

The program '[4628] SWFT Imperium.vshost.exe' has exited with code 0 (0x0).

edit2: first few lines of XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="Swiftech_Imperium.MainWindow"
        Title="SWFT Imperium" Height="435" Width="510" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Icon="Swiftech.ico" Closing="Window_Closing" MouseDown="Grid_MouseDown" WindowStyle="None" BorderThickness="1" BorderBrush="Black" Foreground="Black">
    <Window.Resources>

Upvotes: 0

Views: 671

Answers (1)

aiodintsov
aiodintsov

Reputation: 2605

I suspect that your

channel1List.RemoveAt(1);

code is executed before your

channel1List.Add(new KeyValuePair<double, double>(0, 0));
channel1List.Add(new KeyValuePair<double, double>(DMIN1, 0));
channel1List.Add(new KeyValuePair<double, double>(DMAX1, 100));
channel1List.Add(new KeyValuePair<double, double>(30, 100));

which causes this exception

Make sure that order of execution is always correct, for example by calling collection fill method from constructor.

Upvotes: 0

Related Questions