IndexOutOfRangeException when using inheritance
Great job!
Does this library support inheritance? When I use inheritance I get an IndexOutOfRangeException.
Details:
An unhandled exception has occurred while executing the request.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at FileContextCore.Storage.Internal.FileContextTable`1.<>c__DisplayClass29_0.<ApplyValueConverter>b__1(Object value, Int32 index)
at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerable`1 source, Func`3 selector)+MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at FileContextCore.Storage.Internal.FileContextTable`1.ApplyValueConverter(Dictionary`2 list, Func`2 conversionFunc)
at FileContextCore.Storage.Internal.FileContextTable`1.ConvertToProvider(Dictionary`2 list)
at FileContextCore.Storage.Internal.FileContextTable`1.<Init>b__27_0(Dictionary`2 list)
at FileContextCore.Storage.Internal.FileContextTable`1.Save()
at FileContextCore.Storage.Internal.FileContextStore.ExecuteTransaction(IList`1 entries, IDiagnosticsLogger`1 updateLogger)
at FileContextCore.Storage.Internal.FileContextDatabase.SaveChangesAsync(IList`1 entries, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(DbContext _, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Todo.ServiceLayer.ActionController.Post(Action entity) in
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)```
Can you provide more details for reproduction of your problem?
I'm getting the same error.
Repro:
using FileContextCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Threading.Tasks;
namespace FileContextError
{
class Program
{
static async Task Main(string[] args)
{
var dbContextOptionsBuilder = new DbContextOptionsBuilder<Db>().UseFileContextDatabase();
using var db = new Db(dbContextOptionsBuilder.Options);
db.AddRange(
new ChildClass(),
new ChildClass(),
new ChildClass(),
new ChildClass()
);
await db.SaveChangesAsync();
}
}
class Db : DbContext
{
public Db(DbContextOptions<Db> options) : base(options){}
public DbSet<BaseClass> BaseClasses { get; set; }
public DbSet<ChildClass> ChildClasses { get; set; }
}
public abstract class BaseClass
{
public Guid Id { get; protected set; }
}
public class ChildClass : BaseClass
{
public string Name { get; set; }
}
}
Obs: The error starts to occur when defining any property in the child class.
Hi. Thank you for the reproduction. That's something I can work with. I'll take a look into it.
Great library! I really could use it on the project i am working at. But i have the same problem with inheritance. Any update comming soon to resolve this issue? Thanks!