C# 调用 FileHelperEngine 构造函数时 PresentationFramework.dll 中的 XamlParseException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17993622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XamlParseException in PresentationFramework.dll when calling FileHelperEngine constructor
提问by gus
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'.
PresentationFramework.dll 中发生了“System.Windows.Markup.XamlParseException”类型的第一次机会异常
附加信息:“对与指定绑定约束匹配的“filehelpertest.MainWindow”类型的构造函数的调用引发了异常。行号“3”和行位置“9”。
Hi all,
大家好,
I am new to FileHelpers.
我是 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.
为了隔离这个问题,我在 VS Express 2013 中做了一个最小的 WPF 项目。该代码是从 FileHelpers 文档中的“分隔文件的快速入门”部分复制的。
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?
我尝试引用 FileHelpers.dll 的 3 个不同版本(2.0、1.1、Mono1.2),并尝试重新启动。但是没有我能看到的效果。一定有一些非常简单的东西我错过了对吧?
Or does FileHelpers not work for newer versions of .NET?
或者 FileHelpers 不适用于较新版本的 .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;
}
}
}
采纳答案by gus
The solution to my problem is same as the accepted answer at XAML Parse Exception - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
我的问题的解决方案与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.
我做了 CTRL-ALT-E 然后检查了一切。现在弹出窗口显示实际异常而不是 xamlparseexception。
回答by Marcos Meli
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);
}
}
}