Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect number of constructor arguments on a record type despite a default value is specified for missing arguments. #2287

Open
miklcct opened this issue Sep 11, 2024 · 2 comments
Labels

Comments

@miklcct
Copy link

miklcct commented Sep 11, 2024

Describe the bug
The class cannot load CSVs with missing columns into record types, despite the record type having a default argument for optional columns.

To Reproduce

public record Route(
    string route_id, string agency_id, RouteType route_type,
    string? route_short_name = null, string? route_long_name = null, string? route_desc = null,
    string? route_url = null, string? route_color = null, string? route_text_color = null,
    DropOffPickupType? continuous_pickup = null, DropOffPickupType? continuous_drop_off = null
);
route_id,agency_id,route_short_name,route_long_name,route_type,route_text_color,route_color,route_url,route_desc
1,=GW,GWR,Great Western Railway,2,,0a493e,,

Expected behaviour
A record should be loaded, with the default values used for missing columns.

Actual behaviour
An exception is thrown.

 ---> System.ArgumentException: Incorrect number of arguments for constructor
   at System.Dynamic.Utils.ExpressionUtils.ValidateArgumentCount(MethodBase method, ExpressionType nodeKind, Int32 count, ParameterInfo[] pis)
   at System.Dynamic.Utils.ExpressionUtils.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection`1& arguments, String methodParamName)
   at System.Linq.Expressions.Expression.New(ConstructorInfo constructor, IEnumerable`1 arguments)
   at CsvHelper.Expressions.ObjectRecordCreator.CreateCreateRecordDelegate(Type recordType)
   at CsvHelper.Expressions.RecordCreator.GetCreateRecordDelegate[T](Type recordType)
   at CsvHelper.Expressions.RecordManager.GetReadDelegate[T](Type recordType)
   at CsvHelper.CsvReader.GetRecordsAsync[T](CancellationToken cancellationToken)+MoveNext()
@miklcct miklcct added the bug label Sep 11, 2024
@JoshClose
Copy link
Owner

What are DropOffPickupType and RouteType?

@miklcct
Copy link
Author

miklcct commented Sep 20, 2024

What are DropOffPickupType and RouteType?

They are enums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants