Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException with custom ISerializer #37

Open
mike-the-automator opened this issue Sep 12, 2021 · 1 comment
Open

NullReferenceException with custom ISerializer #37

mike-the-automator opened this issue Sep 12, 2021 · 1 comment

Comments

@mike-the-automator
Copy link

I am trying to implement a custom ISerializer (CustomSerializer class) to accommodate a different format of the JSON file on disk. I added the following code to my ConfigureServices method to attempt to register my custom serializer.

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddDbContext<Context>(options => 
                options.UseFileContextDatabase<CustomSerializer,DefaultFileManager>(location:"C:\\Custom\\Location"))
                       .AddTransient<ISerializer,CustomSerializer>();

        }

When trying to access my model I get a NullReferenceException like the below stack trace. I'm sure I'm missing something in the registration of the CustomSerializer because the break points in my CustomSerializer class are never hit and the DefaultStoreManager.Initialize method throwing the exception attempts to retrieve the ISerializer from the IServiceProvider.

Any help would be much appreciated.

NullReferenceException: Object reference not set to an instance of an object.

    FileContextCore.StoreManager.DefaultStoreManager.Initialize(IFileContextScopedOptions options, IEntityType entityType, object keyValueFactory)
    FileContextCore.Storage.Internal.FileContextTable<TKey>.Init()
    FileContextCore.Storage.Internal.FileContextTable<TKey>..ctor(IPrincipalKeyValueFactory<TKey> keyValueFactory, bool sensitiveLoggingEnabled, IEntityType entityType, IFileContextScopedOptions options, IServiceProvider serviceProvider)
    FileContextCore.Storage.Internal.FileContextTableFactory+<>c__DisplayClass7_0<TKey>.<CreateFactory>b__0()
    FileContextCore.Storage.Internal.FileContextTableFactory.Create(IEntityType entityType)
    FileContextCore.Storage.Internal.FileContextStore.EnsureTable(object key, IEntityType entityType)
    FileContextCore.Storage.Internal.FileContextStore.GetTables(IEntityType entityType)
    FileContextCore.Query.Internal.FileContextShapedQueryCompilingExpressionVisitor.Table(QueryContext queryContext, IEntityType entityType)
    lambda_method(Closure , QueryContext )
    Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync<TResult>(Expression query, CancellationToken cancellationToken)
    Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
    Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<TResult>.GetAsyncEnumerator(CancellationToken cancellationToken)
    Microsoft.EntityFrameworkCore.Internal.InternalDbSet<TEntity>.System.Collections.Generic.IAsyncEnumerable<TEntity>.GetAsyncEnumerator(CancellationToken cancellationToken)
    System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable<T>.GetAsyncEnumerator()
    Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync<TSource>(IQueryable<TSource> source, CancellationToken cancellationToken)
    GroceryStoreAPI.Controllers.CustomerController.GetCustomers() in CustomerController.cs

                return await _context.Customers.ToListAsync();

lambda_method(Closure , object )
Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable+Awaiter.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask<IActionResult> actionResultValueTask)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
@ashislam
Copy link

ashislam commented Jun 3, 2022

got any solutions? I am facing similar issue with custom file manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants