Closed davesmits closed 5 months ago
Not just in the context of MongoDB, imo. I have a similar issue when just enumerating the output of FastDynamicObject
.
using var reader = _fileService.OpenStreamReader(filePath);
using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture) {
Delimiter = delimiter,
IgnoreBlankLines = true,
HasHeaderRecord = hasHeaders
});
var records = (await csv.GetRecordsAsync<dynamic>().ToListAsync())
.Select(d => d as IDictionary<string, object>);
foreach (var recordDic in records) {
// This next line throws
foreach (var (key, value) in recordDic) {
// Do something...
}
}
System.NotSupportedException
Specified method is not supported.
at CsvHelper.FastDynamicObject.System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.GetEnumerator()
People use things in ways I never expect! I'll implement the rest of IDictionary<string, object>
.
I have pushed the changes. Can you pull down the source and test if this satisfies your needs?
@JoshClose wauw that is fast. I will give it a spin; but weekend just started so need to do it somewhere between some other obligations
Fixed in 32.0.1 on NuGet. If there are more issues, open this back up and I'll fix them.
Works for me! thanks
Yep, thank you.
Describe the bug in !https://github.com/JoshClose/CsvHelper/commit/d3852d37ad33df04b069882c6a276d27a706f8ed the
FastDynamicObject
was introduced. Before that theExpandoObject
was used.The Mongo driver was able to serialize ExpandoObject. The FastDynamicObject isn't able to serialize to bson
To Reproduce
First it breaks because the
FastDynamicObject
isnt allowed by default. That is easy to fix by adding it to the allowed typesThen it breaks with this stacktrace
Expected behavior Expect that it keeps working as is and be able to serialize to BSON