Open
Description
An ArgumentOutOfRangeException
occurs when executing a SenseNet client query function like Task<IContentCollection<Content>> QueryAsync(QueryContentRequest requestData, CancellationToken cancel)
. This error is triggered if any of the collected content's selected reference fields are not set.
My Query Details
- Expand Fields:
ArticleReference
- Select Fields:
Path, Type, Name, Id, DisplayName, ParentPath, Hidden, Index, ArticleReference/Path, ArticleReference/Type, ArticleReference/Name, ArticleReference/Id, ArticleReference/DisplayName, ArticleReference/ParentPath, ArticleReference/Hidden, ArticleReference/Index, LinkOpenType, Alt, Title, Href, HrefTitle, Description
Probable Cause
The error is likely thrown in the method SenseNet.Client.Repository.CreateContentFromResponse(Object jObject, Type defaultContentType)
.
Stack Trace
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Newtonsoft.Json.Linq.JContainer.GetItem(Int32 index)
at Newtonsoft.Json.Linq.JArray.get_Item(Int32 index)
at SenseNet.Client.Content.GetReference(Object input, Type propertyType)
at SenseNet.Client.Content.SetProperties(Object responseContent)
at CallSite.Target(Closure, CallSite, Content, Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
at CallSite.Target(Closure, CallSite, Content, Object)
at SenseNet.Client.Content.InitializeFromResponse(Object responseContent)
at CallSite.Target(Closure, CallSite, Content, Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
at CallSite.Target(Closure, CallSite, Content, Object)
at SenseNet.Client.Repository.CreateContentFromResponse(Object jObject, Type defaultContentType)
at SenseNet.Client.Repository.CreateContentFromResponse[T](Object jObject)
at System.Linq.Enumerable.SelectIListIterator`2.Fill(IList`1 source, Span`1 results, Func`2 func)
at System.Linq.Enumerable.SelectIListIterator`2.ToArray()
at SenseNet.Client.Repository.LoadCollectionAsync[T](ODataRequest requestData, CancellationToken cancel)
at [MyContentClass]
Steps to Reproduce
- Create a query with the specified expand and select fields.
- Execute the query using
QueryAsync
method. - Ensure at least one of the collected content's reference fields is unset.
- Observe the
ArgumentOutOfRangeException
thrown.
Expected Behavior
The query should handle cases where reference fields are unset without throwing an exception.
Environment
- Library Version: [SenseNet.Client, Version=3.0.7.2]
- .NET Version: [8.0]
This version includes a clear structure, detailed description, probable cause, and steps to reproduce the issue, making it easier for the maintainers to understand and address the problem.