4

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'The invocation of the constructor on type 'filehelpertest.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.

Hi all,

I am new to FileHelpers.

I made a minimal WPF project in VS Express 2013 in order to isolate this problem. The code is copied from their "Quick Start for Delimited files" section in the FileHelpers docs.

I have tried referencing the 3 different versions of FileHelpers.dll (2.0, 1.1, Mono1.2), and I have tried rebooting. But there is no effect that I can see. There must be something really simple I'm missing right?

Or does FileHelpers not work for newer versions of .NET?

Thanks!

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using FileHelpers;

namespace filehelpertest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            FileHelperEngine engine = new FileHelperEngine(typeof(Customer));
            // To Read Use:
            Customer[] res = engine.ReadFile("f1.txt") as Customer[];
            // To Write Use:
            engine.WriteFile("f2.txt", res);
        }

        [DelimitedRecord(",")]  
        public class Customer
        {
            public int CustId;
            public string Name;
        }
    }
}
Doochz
  • 1,039
  • 2
  • 14
  • 25
  • I expect there's more information in the exception - an inner exception indicating what went wrong in the MainWindow constructor. You should look at that. – Jon Skeet Aug 01 '13 at 12:13
  • Thanks, I agree, but I don't know where / how to see more info... Here is a screenshot: http://i.imgur.com/s7LUOzV.png – Doochz Aug 01 '13 at 12:24
  • 1
    So you choose the "Break" option and you should get more information... – Jon Skeet Aug 01 '13 at 12:47
  • After choosing "Break", I get to a page that says PDB file couldn't be loaded. Then I messed something up by selecting a symbol server thing. And now, when I choose "Break", I see "Source not available"... I can't find a way to undo the symbol server thing... (Thanks BTW) – Doochz Aug 01 '13 at 15:39
  • That sounds very odd. If you allow it to continue instead, do you get a full stack trace *somewhere*? (e.g. in the Output window?) – Jon Skeet Aug 01 '13 at 15:42
  • I have deselected "Microsoft Symbol Server", but it's still not going back to the error page I had earlier about PDB could not be loaded. So this is what I see now when I choose continue: http://i.imgur.com/l7VN705.png – Doochz Aug 01 '13 at 15:44
  • Hi Jon, thanks, I can see the actual exception in the Output window if I choose "Continue"! This is what I need to continue learning to use FileHelpers! Although this raises another question, it would be ideal if the actual exception popper up as is normal instead of being hidden behind xamlparseexception. Is this a known issue with FileHelpers? – Doochz Aug 01 '13 at 15:50
  • I don't think that's a matter of FileHelper - I suspect it's a matter of the execution flow of XAML parsing. I suspect you'd have the same issue if you just threw any exception directly in your constructor. – Jon Skeet Aug 01 '13 at 15:51
  • Hi Jon, you are correct, I put throw new Exception("blah"); inside my public MainWindow(), and the error prompt was also wrapped as xamlparseexception. So it isn't FileHelpers sepcific, it has to do with exceptions occurring from my MainWindow() constructor. Is this normal? – Doochz Aug 05 '13 at 06:14

2 Answers2

14

The solution to my problem is same as the accepted answer at XAML Parse Exception - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

I did CTRL-ALT-E then checked everything. Now the pop-up window shows the actual exception rather than xamlparseexception.

Community
  • 1
  • 1
Doochz
  • 1,039
  • 2
  • 14
  • 25
1

I think that the problem is with the path, provide the full path to the engine and use the generic verion like that:

   public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            try
            {
              var engine = new FileHelperEngine<Customer>();
              // To Read Use:
              Customer[] res = engine.ReadFile(@"c:\yourpath\f1.txt");
              // To Write Use:
              engine.WriteFile(@"c:\yourpath\f2.txt", res);
            }
            catch(Exception ex)
            {
              MessageBox.Show(ex.Message);
            }
        }
    }
Marcos Meli
  • 3,468
  • 24
  • 29
  • Thank you, the actual error in my above code was that the text file had field names as first row, and so could not be parsed as integer (custID). I placed the text file in the Debug folder together with the exe, so the plain filename worked ok. Jon Skeet has helped me find that the actual exception is shown in Output window if I choose "Continue". However I would like to ask if errors being hidden behind xamlparseexception is a known issue with using FileHelpers with VisualStudio. And is there anything I can do to get the exceptions to show up the normal way that they should? – Doochz Aug 01 '13 at 15:52