"Cannot access a disposed object. Object name: 'MySqlConnection'." when trying to persist 35 MB to MariaDb.
See original GitHub issueSteps to reproduce
Please take a look at https://github.com/jp7677/hellocoreclr/tree/mariadb. When running the app I can reproduce the error by enter some text and press the “Say Hello” button. Entity and dataservice are pretty straight forward (relevant parts):
public class Greeting
{
public int GreetingId { get; set; }
public byte[] SomeHugeFile { get; set; }
}
var somehugeFile = new byte[35* 1000 * 1000];
using(var db = dbContextFactory.CreateHelloWorldDbContext())
{
db.Greetings.Add(new Greeting
{
Name = greeting,
TimestampUtc = DateTime.Now.ToUniversalTime(),
SomeHugeFile = somehugeFile
});
await db.SaveChangesAsync();
}
The issue
I’m trying to save 35MB to the database in an ASP.Net Core request, unfortunately it ends with a ObjectDisposedException.
An unhandled exception was thrown by the application.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'MySqlConnection'.
at MySql.Data.MySqlClient.MySqlConnection.VerifyNotDisposed()
at MySql.Data.MySqlClient.CommandExecutors.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.CommandExecutors.TextCommandExecutor.<ExecuteNonQueryAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlCommand.<ExecuteNonQueryAsync>d__46.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at MySql.Data.MySqlClient.MySqlTransaction.Dispose(Boolean disposing)
at MySql.Data.MySqlClient.MySqlConnection.CloseDatabase()
at MySql.Data.MySqlClient.MySqlConnection.DoClose()
at MySql.Data.MySqlClient.MySqlConnection.Dispose(Boolean disposing)
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalConnection.Dispose()
at Microsoft.Extensions.DependencyInjection.ServiceProvider.Dispose()
at Microsoft.EntityFrameworkCore.DbContext.Dispose()
at HelloCoreClrApp.Data.DataService.<SaveGreetingAsync>d__5.MoveNext() in /home/jpeters/Develop/hellocoreclr/src/HelloCoreClrApp/Data/DataService.cs:line 61
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at HelloCoreClrApp.WebApi.Actions.SayHelloWorldAction.<SaveGreetingAsync>d__4.MoveNext() in /home/jpeters/Develop/hellocoreclr/src/HelloCoreClrApp/WebApi/Actions/SayHelloWorldAction.cs:line 34
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at HelloCoreClrApp.WebApi.Actions.SayHelloWorldAction.<ExecuteAsync>d__3.MoveNext() in /home/jpeters/Develop/hellocoreclr/src/HelloCoreClrApp/WebApi/Actions/SayHelloWorldAction.cs:line 26
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at HelloCoreClrApp.WebApi.HelloWorldController.<SayHelloWorldAsync>d__3.MoveNext() in /home/jpeters/Develop/hellocoreclr/src/HelloCoreClrApp/WebApi/HelloWorldController.cs:line 26
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
2017-03-31 11:17:22 +02:00|Debug|10|0HL3O2QSK80BB|Microsoft.AspNetCore.Server.Kestrel
Further technical details
MySQL version: MariaDb 10.1.22-MariaDB-1~jessie - mariadb.org binary distribution Operating system: Fedora 25/Docker Pomelo.EntityFrameworkCore.MySql version: PackageReference Include=“MySqlConnector” Version=“0.15.1” PackageReference Include=“Pomelo.EntityFrameworkCore.MySql” Version=“1.1.1-prerelease-10026”
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Masstransit. Cannot access a disposed object. Object name
It would seem that everything is simple, but I get an error "Cannot access a disposed object. Object name: 'MySqlConnection'.
Read more >ObjectDisposedException In MySqlConnection.Finalize
The exception dump is below: System.ObjectDisposedException(0x80131622): Cannot access a disposed object. Object name: 'System.Net.Sockets.
Read more >dbForge Studio for MySQL History
225 12-Feb-09. User-reported bug fixes. 'Cannot access a disposed object' error is fixed while working with windows (37379); NullReferenceException error ...
Read more >Cannot access a disposed object
Cannot access a disposed object. Object name:'_ProgressBar' What I have tried: I tried deleting MySQL folder from %appdata%.
Read more >Chapter 27. Connectors
The ODBC configuration file stores the driver and database information required to connect to the server. It is used by the Driver Manager...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, cool! Thanks a lot. Its a pleasure to use this project (and the underlying MySqlConnector of course ) and to work with you!
I’ve opened #247, my local copy of your test with that commit now produces: