IndexOutOfRangeException error when reading all rows from table in EF Core 2.0 RRS feed

  • Question

  • User-1142747527 posted

    I have a Web API targetting .Net Core 2.0. The data source is a MySQL database, and I'm using Pomelo.EntityFrameworkCore.MySql

    I can load data from all the tables in my database except for one. I don't know why, but when I try to load all records in this database, by executing a simple:

    public class MyContext : DbContext
        public DbSet<Condition> Condition { get; set; }
    public class MyController : Controller
        private readonly MyContext _context;
        // GET: api/Sync
    public async Task<IActionResult> GetChangeSet() { List<Condition> conditions = _context.Condition.ToList(); } }

    I get the following error:

        _context.Condition.ToList()' threw an exception of type 'System.IndexOutOfRangeException'

        Data: {System.Collections.ListDictionaryInternal}
        HResult: -2146233080
        HelpLink: null
        InnerException: null
        Message: "Index was outside the bounds of the array."
        Source: "Anonymously Hosted DynamicMethods Assembly"
        StackTrace: "   at lambda_method(Closure , ValueBuffer )\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalMixedEntityEntry..ctor(IStateManager stateManager, IEntityType entityType, Object entity, ValueBuffer valueBuffer)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryFactory.NewInternalEntityEntry(IStateManager stateManager, IEntityType entityType, Object entity, ValueBuffer valueBuffer)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryFactory.Create(IStateManager stateManager, IEntityType entityType, Object entity, ValueBuffer valueBuffer)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTrackingFromQuery(IEntityType baseEntityType, Object entity, ValueBuffer valueBuffer, ISet`1 handledForeignKeys)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.EntityTrackingInfo.StartTracking(IStateManager stateManager, Object entity, ValueBuffer valueBuffer)\r\n   at Microsoft.EntityFrameworkC
    ore.Query.Internal.QueryBuffer.StartTracking(Object entity, EntityTrackingInfo entityTrackingInfo)\r\n   at Microsoft.EntityFrameworkCore.Query.QueryContext.StartTracking(Object entity, EntityTrackingInfo entityTrackingInfo)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()\r\n   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)"
        TargetSite: {Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ISnapshot lambda_method(System.Runtime.CompilerServices.Closure, Microsoft.EntityFrameworkCore.Storage.ValueBuffer)}

    This is what my Condition model looks like:

    namespace Inspections.Data.Models
        public class Condition
            public int Id { get; set; }
            public string ConditionName { get; set; }
            public int? GroupId { get; set; }
            public virtual Group Group { get; set; }
            public int? AddedById { get; set; }
            public virtual User AddedBy { get; set; }
            public DateTime AddedDate { get; set; }
            public int? DeletedById { get; set; }
            public virtual User DeletedBy { get; set; }
            public DateTime? DeletedDate { get; set; }
            public DateTime? ModifiedDate { get; set; }

    The exact same thing works perfectly when reading from all the other tables in the database. And the table is populated with a number of rows...

    Any ideas?

    Thursday, November 2, 2017 10:36 AM


  • User-1142747527 posted

    Sorry, found the problem. Was just a typo :/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 2, 2017 10:42 AM