PageSize with an Expand on nullable embeds results in TargetInvocationException

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When using a [MongoEnableQuery(PageSize = 256)] on a controller that serves documents with nullable embeds, an odata $expand on a nullable results in a TargetInvocationException. 

      It seems that the ODataQueryOptions (specifically HandleNullPropagationOption?) get lost when specifing a PageSize option [MongoEnableQuery(PageSize = 256)] 

      Example odata test url: {{Endpoint{}}}/odata/Case?$expand=location($expand=address)

      It results in a TargetInvocationException when using an expand on address with a null location. If the embed location is present it works with a PageSize setting regardless.

       

      The issue seems related to the pageSize setting, since removing that attribute resolves the issue. But of course we'd also like use a PageSize setting, so thats not a workable workaround.

      [MongoEnableQuery] /// works
      [MongoEnableQuery(PageSize = 256)] /// TargetInvocationException

      Document structure

      public Class Case 
      {
          ///
          public Location? location { get; set; }
      }
      public class Location
      {
          ///
          public IEnumerable<Address>? Address { get; set; } = [];
      }
      public class Address
      {
          ///
      }
      

      Stacktrace

      System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
       ---> System.ArgumentNullException: Value cannot be null. (Parameter 'source')
         at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
         at lambda_method37(Closure, Zitting)
         at System.Linq.Enumerable.IteratorSelectIterator`2.MoveNext()
         at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
         at Microsoft.AspNetCore.OData.Query.Container.TruncatedCollection`1..ctor(IQueryable`1 source, Int32 pageSize, Boolean parameterize)
         at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.LimitResults[T](IQueryable`1 queryable, Int32 limit, Boolean parameterize, Boolean& resultsLimited)
         at InvokeStub_ODataQueryOptions.LimitResults(Object, Object, IntPtr*)
         at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
         --- End of inner exception stack trace ---

      Relevant versions

      .net10
      MongoDB.Driver" Version="3.8.1"
      MongoDB.AspNetCore.OData" Version="1.1.2"
      Microsoft.AspNetCore.OData" Version="9.4.1"

              Assignee:
              Oleksandr Poliakov
              Reporter:
              Evert Rozendaal (EXT)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: