Skip to content

System.NotSupportedException on second collection in a collection a few properties deep #6589

Closed as not planned

Description

@Ripper555

Method below with notes where the exception is happening.

System.NotSupportedException: Collection was of a fixed size.
   at System.SZArrayHelper.Add[T](T value)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.ClrICollectionAccessor`3.AddRange(Object instance, IEnumerable`1 values)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.AddRangeToCollection(Object entity, INavigation navigation, IEnumerable`1 values, Boolean tracking)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.LoadNavigationProperties(Object entity, IReadOnlyList`1 navigationPath, Int32 currentNavigationIndex, IReadOnlyList`1 relatedEntities, Boolean tracking)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.<>c__DisplayClass11_0.<Include>b__0(EntityLoadInfo eli)
   at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.Include(QueryContext queryContext, Object entity, IReadOnlyList`1 navigationPath, IReadOnlyList`1 relatedEntitiesLoaders, Int32 currentNavigationIndex, Boolean queryStateManager)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.<>c__DisplayClass11_0.<Include>b__0(EntityLoadInfo eli)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.Include(QueryContext queryContext, Object entity, IReadOnlyList`1 navigationPath, IReadOnlyList`1 relatedEntitiesLoaders, Int32 currentNavigationIndex, Boolean queryStateManager)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.<>c__DisplayClass11_0.<Include>b__0(EntityLoadInfo eli)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.Include(QueryContext queryContext, Object entity, IReadOnlyList`1 navigationPath, IReadOnlyList`1 relatedEntitiesLoaders, Int32 currentNavigationIndex, Boolean queryStateManager)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.Include(QueryContext queryContext, Object entity, IReadOnlyList`1 navigationPath, IReadOnlyList`1 relatedEntitiesLoaders, Boolean queryStateManager)
   at Microsoft.EntityFrameworkCore.Query.Internal.GroupJoinInclude.GroupJoinIncludeContext.Include(Object entity)
   at Microsoft.EntityFrameworkCore.Query.Internal.GroupJoinInclude.GroupJoinIncludeContext.Include(Object entity)
   at Microsoft.EntityFrameworkCore.Query.Internal.GroupJoinInclude.GroupJoinIncludeContext.Include(Object entity)
   at Microsoft.EntityFrameworkCore.Query.Internal.GroupJoinInclude.GroupJoinIncludeContext.Include(Object entity)
   at Microsoft.EntityFrameworkCore.Query.Internal.GroupJoinInclude.GroupJoinIncludeContext.Include(Object entity)
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_GroupJoin>d__26`4.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__22`3.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at EmCollect.Domain.Concrete.EmRepo.GetState(Expression`1 where) in F:\Source\Repos\EmCollect\EmCollect\EmCollect.Domain\Concrete\EmRepo.cs:line 123
   at EmCollect.Domain.Concrete.EmRepo.GetLastStates(Int32 days) in F:\Source\Repos\EmCollect\EmCollect\EmCollect.Domain\Concrete\EmRepo.cs:line 113
   at EmCollect.UI.Dashboard.DataRecoveryViewModel.ViewStates() in F:\Source\Repos\EmCollect\EmCollect\EmCollect.UI\Dashboard\DataRecoveryViewModel.cs:line 39
private IList<ProgramState> GetState(Expression<Func<ProgramState, bool>> where)
    {
      return _context.States.Where(where)
        .Include(x => x.SiteReport)
          .ThenInclude(r => r.Run)
            .ThenInclude(run => run.OxygenDataSet)

          .Include(x => x.SiteReport.Calibration)
            .ThenInclude(cal => cal.BiasChecks) //BiasChecks is ICollection
              .ThenInclude(bias => bias.CalibrationPoints) //CalibrationPoints is ICollection
          .Include(x => x.SiteReport.Calibration)
             .ThenInclude(cal => cal.BiasChecks)
              //.ThenInclude(bias => bias.O2DataSet) O2DataSet is ICollection. This is the line that throws the exception.

          .Include(x => x.SiteReport.Calibration)
            .ThenInclude(cal => cal.CalibrationErrorCheck)
              .ThenInclude(cec => cec.CalibrationPoints)
          .Include(x => x.SiteReport.Calibration.CalibrationErrorCheck)
              .ThenInclude(cec => cec.O2DataSet)

          .Include(x => x.SiteReport.Calibration).ThenInclude(cal => cal.Cylinders).ThenInclude(cyl => cyl.Contents)
          .Include(x => x.SiteReport.Calibration).ThenInclude(cal => cal.Cylinders).ThenInclude(cyl => cyl.Cert)
          .Include(x => x.SiteReport.Calibration.CalibrationSettings)
        .Include(x => x.SiteReport.Run).ThenInclude(run => run.Emissions)

        .Include(x=>x.SiteReport.UserInputs)
        .ThenInclude(inputs=> inputs.Ancillarys).ThenInclude(anc=>anc.Documents)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.ClientInfo)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.EnginPictures)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.Equpment)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.FuelAnalysis)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.PermitLimits)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.RegulationLimits)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.SiteInfo)
        .Include(x => x.SiteReport.UserInputs)
        .ThenInclude(inputs => inputs.TesterInfo)
        .ToList(); 
    }

EF Core version: id="Microsoft.EntityFrameworkCore.SqlServer" version="1.0.1" targetFramework="net461"
Operating system: Windows 10
Visual Studio version: 2015
Other details about my project setup:
EF and Context class in separate project with startup project: WPF

Activity

  1. ajcvickers commented on Sep 22, 2016

    @ajcvickers
    Contributor

    @Ripper555 Are any of the collection navigation properties in your entity types arrays or read-only collections? EF needs to be able to add elements to the collections when loading and at other times, so arrays and read-only collections are not supported.

  2. Ripper555 commented on Sep 22, 2016

    @Ripper555
    Author

    I had a default value of an empty array for the property O2DataSet. I changed it to a empty List and it seems to not throw the exception anymore. Thanks for the help!

  3. mrpmorris commented on Sep 8, 2020

    @mrpmorris

    @ajcvickers Could the exception message be more inuitive, please? It took me a while to find the cause of this problem, whereas if it had said something different I might have got it quicker

    "Association property instances cannot be a fixed length type, such as an Array"

    Note how I said "instances" so as not to mislead people into thinking they cannot declare the property type as IEnumerable<T>

  4. ajcvickers commented on Sep 8, 2020

    @ajcvickers
    Contributor

    @mrpmorris This issue is very old. If you're still seeing this exception with EF Core 3.1 or 5.0, then please open a new issue and
    attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions