Non-Generic MemberMap Validate Throws Exception
When trying to configure the Validate() for a MemberMap (the non-generic version), it throws an exception
Expression of type 'System.String' cannot be used for parameter of type 'CsvHelper.ValidateArgs' of method 'Boolean <.ctor>b__0_1(CsvHelper.ValidateArgs)' (Parameter 'arg0')
I believe that the problem lies in how the expression is being created. It should be typeof(ValidateArgs) instead of typeof(string).
https://github.com/JoshClose/CsvHelper/blob/dfd643d1b57a83b7ea5099e92e38f87723baac2c/src/CsvHelper/Configuration/MemberMap.cs#L214
It can be easily tested in an existing test by casting the Map() result to a MemberMap
private sealed class ValidateMap : ClassMap{ public ValidateMap() { ((MemberMap)Map(m => m.Id)).Validate(args => !string.IsNullOrEmpty(args.Field)); Map(m => m.Name); } }
https://github.com/JoshClose/CsvHelper/blob/dfd643d1b57a83b7ea5099e92e38f87723baac2c/tests/CsvHelper.Tests/Reading/ValidateTests.cs#L96-L103
@JoshClose This bug is blocking my company from updating CsvHelper and by proxy updating to .Net 6 . Explicitly listing all the properties is not a feasible workaround for us.
Fixed in next release.