XamlParseException

Jun 19, 2014 at 10:12 AM
Hi to everybody.
My task is to read GPS coordinates about some events from a csv file (which I created myself in an HMI display) and show them on a map.
I started a C# WPF project in Visual Studio 2012 express (Win7 pro 64bit). Linked to the Bing map and managed to show some pushpins on the map when I put coordinates manually.
Next step is to read data from csv file. I installed BGCsv, added code:
        using (var streamReader = new StreamReader("C:\\Typhoon_Log64_148.csv"))
        using (var reader = new CsvReader(streamReader))
        {
            // the CSV file has a header record, so we read that first
            reader.ReadHeaderRecord();

            while (reader.HasMoreRecords)
            {
                var dataRecord = reader.ReadDataRecord();
                var session = dataRecord["Session"];
             } 
          }        
There was no compillation errors, but when running an unhandled exception of type
'System.Windows.Markup.XamlParseException occured in PresentationFramework.dll
What is wrong?
regards, Wal .
Jun 20, 2014 at 12:01 PM
Installed Visual Studio 2012 on another laptop (Win7pro 32bit)
Started a new WPF project, added reference to Kent.Boogaart.KBCsv.dll.
added two lines and brackets to MainWindow():
    using (var streamReader = new StreamReader(""))
    using (CsvReader reader = new CsvReader(streamReader))
    {
    }        
No compilation errors, but unhandled XamlParseException again occured.
Coordinator
Jun 20, 2014 at 1:46 PM
Hi,

Any exception thrown whilst instantiating WPF components will be wrapped in a XamlParseException by the WPF runtime. In this case, you'll get an exception simply because you've not provided a valid path to the StreamReader. I suggest you set your debugger to break on any exception so that you can see the problem more easily before WPF wraps it up in another exception. You may also want to move the logic to a more appropriate place, other than your constructor.

HTH,
Kent
Jun 23, 2014 at 10:33 AM
Dear kentcb, thank You very much for the answer. What settings do You recommend for debugger? And where should I place the code related to csv file?
Jul 28, 2014 at 2:48 PM
Please, advice which version of Visual Studio is required to open the examples for C#?
Aug 21, 2014 at 9:51 AM
I tried to open the C# examples with VS 2008 pro and VS 2012 Express. No success.