Describe the bug
On 20.0.0 creating a CsvConfiguration with an Object initializer or using a "with" statement throws MissingMethod exception.
To Reproduce
Expected behavior
Can create CsvConfiguration with an object initializer
Screenshots
Additional context
Source:
Temp.Lib:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="20.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IsExternalInit" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>
</Project>
using CsvHelper.Configuration;
using System.Globalization;
namespace Temp.Lib
{
public static class ConfigCreator
{
public static CsvConfiguration CreateConfig() => new(CultureInfo.InvariantCulture) { Delimiter = ";" };
}
}
md5-c1177b2e3f8e3b3152d9b2f87ffae510
```csharp
using System;
using Temp.Lib;
namespace Temp
{
public static class Program
{
public static void Main()
{
ConfigCreator.CreateConfig();
Console.WriteLine("Config created successfully");
}
}
}
Suggestion
Maybe instead of a record with init only properties, use a record with get only properties and optional constructor parameters?
I was using a library to get the feature into older version. Doesn't seem to work. I just did it in the source and it seems to work now. I'll include this in the next version that will be out within the next couple of hours. I want to fix the other issues people are seeing with it.
I know, I have used the same nuget, but didn't do extensive testing with it. If you want to keep the CsvConfiguration a record you might want to try making it work. You could try not using the nuget for the init stuff but place the source code directry inside the project, and make the class internal
Yes, I tried that and your example works with it. :)
Ohh, sorry, I misread your comment. Thanks for the quick reactions, and the fix!
Should be fixed in 21.0.0. https://www.nuget.org/packages/CsvHelper/21.0.0