$top is attempted on null collections, resulting in failures like this:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. -->
System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.OrderedEnumerable`2..ctor(Enumerable`1 source, Func` keySelector, IComparer`1comparer, Boolean decending)
at lambda_method(Closure_Site)
--End of inner exception stack trace--
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo. UnsafeInvokeInternal(Object obj, Object [] parameters, Object arguments)
at System.Delegatre.DynamicInvokeImpl
at Microsot.AspNet.OData.Query.Expressions.SelectExpandBinder.Bind
at Microsot.AspNet.OData.Query.ODataQueryOptions.ApplySelectExpand
Description
ProjectCollection does have logic for handling null propagation, but it's currently using the modified source (e.g. the one that wraps the original in OrderBy, Take, Skip). As a result, when the source is null the check doesn't apply prior to the execution of those operations, which all require a non-null collection.
The fix is to simply perform the null check on the original source.
Issues
$top
is attempted on null collections, resulting in failures like this:Description
ProjectCollection
does have logic for handling null propagation, but it's currently using the modified source (e.g. the one that wraps the original inOrderBy
,Take
,Skip
). As a result, when thesource
is null the check doesn't apply prior to the execution of those operations, which all require a non-null collection.The fix is to simply perform the null check on the original
source
.NOTE: The same issue exists in https://github.com/OData/AspNetCoreOData but I'll leave it to maintainers to port the fix.
Checklist (Uncheck if it is not completed)