调试期间的 CsvHelper 错误 - System.Linq.SystemCore_EnumerableDebugView
CsvHelper Error during debug - System.Linq.SystemCore_EnumerableDebugView
在 Visual Studio 2019 年使用 .NET Core 2.2 对 CsvHelper 进行初步测试。
我有一个测试 csv 文件,其中 headers 个名称包含括号。我正在使用 PrepareHeaderForMatch
从名称中删除括号,以便它们匹配我的 class 属性 名称。
在调试过程中,出现以下错误:
Error Evaluation of method System.Linq.SystemCore_EnumerableDebugView`1[PIlibrary.Entity].get_Items() calls into native method Interop+Kernel32.ReadFile(System.Runtime.InteropServices.SafeHandle, byte*, int, int&, System.IntPtr). Evaluation of native methods in this context is not supported.
代码如下:
public static void Main(string[] args)
{
using (var reader = new StreamReader(@"C:\Users\me\Desktop\SD Temp\Data_Weekly\pfilerr.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.PrepareHeaderForMatch = (string header, int index) =>
header.Replace("(", "").Replace(")", "");
var records = csv.GetRecords<Entity>();
}
}
csv文件可以在这里找到,供参考:csv file它只有20行,300多列中填充的不到一半。
实体 class 有超过 300 个属性(以匹配超过 300 列)- 如果需要,我可以 post 在这里,但由于它的长度,我最初选择不这样做.属性的名称与 csv 文件的 headers 相匹配,但某些包含上述括号的名称除外。
我知道这个错误完全有可能与 C# 相关,不一定特定于 CsvHelper - 不过我不确定,因为这是我遇到的第一个错误。
问题是,当您在 Debug 中查看记录时,您看到的是一个 IEnumerable<Entity>
,当您迭代它们时,它只包含 yield
个记录。调试无法为您迭代它们。
CsvHelper Getting Started
The GetRecords<T>
method will return an IEnumerable<T>
that will yield
records. What this means is that only a single record is returned at a time as you iterate the records. That also means that only a small portion of the file is read into memory.
调用 ToList()
或以其他方式迭代记录将它们拉入内存
var records = csv.GetRecords<Entity>().ToList();
在 Visual Studio 2019 年使用 .NET Core 2.2 对 CsvHelper 进行初步测试。
我有一个测试 csv 文件,其中 headers 个名称包含括号。我正在使用 PrepareHeaderForMatch
从名称中删除括号,以便它们匹配我的 class 属性 名称。
在调试过程中,出现以下错误:
Error Evaluation of method System.Linq.SystemCore_EnumerableDebugView`1[PIlibrary.Entity].get_Items() calls into native method Interop+Kernel32.ReadFile(System.Runtime.InteropServices.SafeHandle, byte*, int, int&, System.IntPtr). Evaluation of native methods in this context is not supported.
代码如下:
public static void Main(string[] args)
{
using (var reader = new StreamReader(@"C:\Users\me\Desktop\SD Temp\Data_Weekly\pfilerr.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.PrepareHeaderForMatch = (string header, int index) =>
header.Replace("(", "").Replace(")", "");
var records = csv.GetRecords<Entity>();
}
}
csv文件可以在这里找到,供参考:csv file它只有20行,300多列中填充的不到一半。
实体 class 有超过 300 个属性(以匹配超过 300 列)- 如果需要,我可以 post 在这里,但由于它的长度,我最初选择不这样做.属性的名称与 csv 文件的 headers 相匹配,但某些包含上述括号的名称除外。
我知道这个错误完全有可能与 C# 相关,不一定特定于 CsvHelper - 不过我不确定,因为这是我遇到的第一个错误。
问题是,当您在 Debug 中查看记录时,您看到的是一个 IEnumerable<Entity>
,当您迭代它们时,它只包含 yield
个记录。调试无法为您迭代它们。
CsvHelper Getting Started
The
GetRecords<T>
method will return anIEnumerable<T>
that willyield
records. What this means is that only a single record is returned at a time as you iterate the records. That also means that only a small portion of the file is read into memory.
调用 ToList()
或以其他方式迭代记录将它们拉入内存
var records = csv.GetRecords<Entity>().ToList();