bati
bati
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
Ah I see where you're coming from
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
Not with a factory
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
Also, my error has been resolved by removing pooling
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
That already is registered from another service
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
As in register the context?
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
Ohh I need to use AddDbContextFactory<>() instead
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
webApplicationBuilder.Services.AddPooledDbContextFactory<SionDbContext>((s, o) =>
{
#if MIGRATION
const string connectionString = "raw connection string for now";
#else
var configuration = s.GetRequiredService<IConfigurationRoot>();
var connectionString = new MySqlConnectionStringBuilder
{
Server = configuration["MARIADB_SERVER"] ?? "localhost",
Port = uint.Parse(configuration["MARIADB_PORT"] ?? "3306"),
// Pooling = true,
Database = configuration["MARIADB_NAME"],
UserID = configuration["MARIADB_USERNAME"] ?? "root",
Password = configuration["MARIADB_PASSWORD"]
}.ConnectionString;
#endif

o.UseMySql(connectionString, new MariaDbServerVersion(ServerVersion.AutoDetect(connectionString)));
o.UseLoggerFactory(s.GetRequiredService<ILoggerFactory>());
o.EnableDetailedErrors();
});
webApplicationBuilder.Services.AddPooledDbContextFactory<SionDbContext>((s, o) =>
{
#if MIGRATION
const string connectionString = "raw connection string for now";
#else
var configuration = s.GetRequiredService<IConfigurationRoot>();
var connectionString = new MySqlConnectionStringBuilder
{
Server = configuration["MARIADB_SERVER"] ?? "localhost",
Port = uint.Parse(configuration["MARIADB_PORT"] ?? "3306"),
// Pooling = true,
Database = configuration["MARIADB_NAME"],
UserID = configuration["MARIADB_USERNAME"] ?? "root",
Password = configuration["MARIADB_PASSWORD"]
}.ConnectionString;
#endif

o.UseMySql(connectionString, new MariaDbServerVersion(ServerVersion.AutoDetect(connectionString)));
o.UseLoggerFactory(s.GetRequiredService<ILoggerFactory>());
o.EnableDetailedErrors();
});
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
I'll go ahead and send how I'm injecting the dbcontext factory
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
Found the trace differences just now
With Pooling

at void Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IResettableService.ResetState()
at void Microsoft.EntityFrameworkCore.Internal.DbContextPool<TContext>.Return(IDbContextPoolable context)
at void Microsoft.EntityFrameworkCore.Internal.DbContextLease.Release()
at void Microsoft.EntityFrameworkCore.Internal.DbContextLease.ContextDisposed()
at void Microsoft.EntityFrameworkCore.DbContext.Dispose()

=================================================================================

Without Pooling

at async Task Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IResettableService.ResetStateAsync(CancellationToken cancellationToken)
at async ValueTask Microsoft.EntityFrameworkCore.Internal.DbContextPool<TContext>.ReturnAsync(IDbContextPoolable context, CancellationToken cancellationToken)
at async ValueTask Microsoft.EntityFrameworkCore.DbContext.DisposeAsync()
With Pooling

at void Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IResettableService.ResetState()
at void Microsoft.EntityFrameworkCore.Internal.DbContextPool<TContext>.Return(IDbContextPoolable context)
at void Microsoft.EntityFrameworkCore.Internal.DbContextLease.Release()
at void Microsoft.EntityFrameworkCore.Internal.DbContextLease.ContextDisposed()
at void Microsoft.EntityFrameworkCore.DbContext.Dispose()

=================================================================================

Without Pooling

at async Task Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IResettableService.ResetStateAsync(CancellationToken cancellationToken)
at async ValueTask Microsoft.EntityFrameworkCore.Internal.DbContextPool<TContext>.ReturnAsync(IDbContextPoolable context, CancellationToken cancellationToken)
at async ValueTask Microsoft.EntityFrameworkCore.DbContext.DisposeAsync()
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
Here's after disabling pooling:
23 replies
CC#
Created by bati on 1/23/2025 in #help
Cannot access a disposed context instance.
Yeah I do have pooling toggled on for my database config
23 replies