簡體   English   中英

調用FileHelperEngine構造函數時,PresentationFramework.dll中的XamlParseException

[英]XamlParseException in PresentationFramework.dll when calling FileHelperEngine constructor

PresentationFramework.dll中出現'System.Windows.Markup.XamlParseException'類型的第一次機會異常
附加信息:'對類型'filehelpertest.MainWindow'的構造函數的調用與指定的綁定約束相匹配引發了異常。 行號“3”和行位置“9”。

大家好,

我是FileHelpers的新手。

我在VS Express 2013中制作了一個最小的WPF項目,以便解決這個問題。 代碼將從FileHelpers文檔中的“Quick Start for Delimited files”部分復制。

我試過引用3個不同版本的FileHelpers.dll(2.0,1.1,Mono1.2),我嘗試重啟。 但是我看不到任何影響。 必須有一些非常簡單的東西,我錯過了嗎?

或者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;
        }
    }
}

我的問題的解決方案與XAML Parse Exception中接受的答案相同- xmlns:x =“http://schemas.microsoft.com/winfx/2006/xaml”

我做了CTRL-ALT-E然后檢查了一切。 現在,彈出窗口顯示實際異常,而不是xamlparseexception。

我認為問題在於路徑,提供引擎的完整路徑並使用類似的通用版本:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM