In GeoTab.Checkmate.ObjectModel ver. 11.118.421, the following valid Sort constructor call throws an ArgumentException:
Sort sortOptions = new Sort(SortField.IdSortField,
SortDirection.Asc,
null,
null);This is because of a logic bug in the following Sort constructor code
public Sort(string sortBy, SortDirection? direction = global::Geotab.Checkmate.ObjectModel.SortDirection.Asc, string? offset = null, Id? lastId = null)
{
if (SortField.ImplementedSortFields.Contains<string>(sortBy, StringComparer.InvariantCultureIgnoreCase))
{
throw new ArgumentException("Use existing implementation of ISort for this field");
}
SortBy = sortBy;
SortDirection = direction;
Offset = offset;
LastId = lastId;
}In the if statement, SortField.ImplementedSortFields is a string array that contains all the valid sortBy field names, which means that the exception should only be thrown when Contains returns false. So, for this to work correctly, the return value of Contains should have been inverted, meanting the if statement should look lie this:
if (!SortField.ImplementedSortFields.Contains<string>(sortBy, StringComparer.InvariantCultureIgnoreCase))
{
throw new ArgumentException("Use existing implementation of ISort for this field");
}I've been able to work around this by passing an invalid sortBy value and then changing the SortBy property value
Sort sortOptions = new Sort("invalid",
SortDirection.Asc,
null,
null);
sortOptions.SortBy = SortField.IdSortField;A possible better implementation would have been to use an enumeration of valid sortable field names. That way, invalid values can't be passed in, and it would be caught at compile time instead of run time.
