2013-08-01 21 views
4

的類型 「System.Windows.Markup.XamlParseException」第一次機會異常出現在 PresentationFramework.dll
其他信息時:「的 對類型構造函數調用'filehelpertest.MainWindow'與 匹配指定的綁定約束引發異常。'行號「3」和 行位置「9」。XamlParseException在PresentationFramework.dll調用FileHelperEngine構造

大家好,

我是新來FileHelpers。

我在VS Express 2013中做了一個最小的WPF項目,以便隔離這個問題。 代碼從FileHelpers文檔中的「分隔文件快速入門」部分複製而來。

我已經嘗試引用FileHelpers.dll(2.0,1.1,Mono1.2)的3個不同版本,並且我嘗試了重新啓動。但是我看不到任何效果。必須有一些非常簡單的東西我錯過了嗎?

或者FileHelpers不適用於較新版本的.NET?

謝謝!

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; 
     } 
    } 
} 
+0

我期望異常中有更多信息 - 一個內部異常,指出MainWindow構造函數中出錯的地方。你應該看看那個。 –

+0

謝謝,我同意,但我不知道在哪裏/如何看到更多信息...這是一個截圖:http://i.imgur.com/s7LUOzV.png – gus

+1

所以你選擇「休息」選項和你應該得到更多的信息.​​.. –

回答

1

我認爲這個問題是與路徑,提供完整路徑引擎,並使用通用的優化版本那樣:

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); 
      } 
     } 
    } 
+0

謝謝你,我上面的代碼中的實際錯誤是,文本文件的字段名稱是第一行,所以無法解析爲整數(custID)。我將文本文件與exe文件放在Debug文件夾中,所以普通文件名工作正常。如果我選擇「繼續」,Jon Skeet幫助我發現實際的異常會顯示在「輸出」窗口中。不過,我想問一下在xamlparseexception後面隱藏的錯誤是VisualStudio使用FileHelpers的已知問題。有什麼我可以做的,讓異常顯示他們應該正常的方式? – gus

+0

@MarcosMeli設置例外是個好主意。 –