The exception that is thrown when an operation is performed on a disposed object.
Questions tagged [objectdisposedexception]
190 questions
1
vote
3 answers
C#/WPF app throwing a ObjectDisposedException; why am I not able to catch or get a stacktrace?
I have a C# WPF UI app, and when I close it, I always get a windows application-crash dialog ("UIDemo has encountered a problem and needs to close.").
The error report indicates that it's a System.ObjectDisposedException which indicates that…

Grant Birchmeier
- 17,809
- 11
- 63
- 98
1
vote
1 answer
unable to query EntityFramework shared dbcontext reliably
I'm trying to share a simple DbContext with 4 DbSets among multiple repositories, each of my repositories inherit from this base class
public class CodeFirstRepository : IDisposable
{
private static MyContext _ctx = new MyContext();
…

Jason
- 15,915
- 3
- 48
- 72
1
vote
0 answers
"Clients" is throwing System.ObjectDisposed exception in signalr hub
[nevermind I just requested the data from the front-end and handled it from controllers. It works.No need to get data through this hub.
Although I like to know how it can be done from hub.
using IdentityCore.DbLayer.Entity;
using…

Smarpan Sharma
- 21
- 4
1
vote
2 answers
Prevent object dispose inside using block
Workflow:
I have a winform app with two forms, in the 1st form I query a liteDB and it manipulates an IEnumerable instance inside a using block with retrieved data.
IEnumerable searchResult;
using(var db = new…

Shahaboddin
- 136
- 1
- 9
1
vote
0 answers
System.ObjectDisposedException: Safe handle has been closed occurs when I try to open SQL Teradata connection using TdConnection class
I have a C# console application trying to connect to SQL Teradata using TdConnection class.
Below is my code:
using (TdConnection conn = new TdConnection(connstr))
{
using (TdCommand tdCmd = new TdCommand(selectQry))
{
using…

Yograj Varsolkar
- 23
- 3
1
vote
1 answer
Cannot access a disposed object. Object name: 'SslStream'
We have an service bus triggered Azure function which makes a call to an http triggered Azure function and from times to times we are experiencing the error below,
The operation was canceled. The read operation failed, see inner
exception. Cannot…

Konstantinos Ventouris
- 41
- 2
- 4
1
vote
2 answers
Dispose context instance error when trying to connect to my DB after Azure service bus message is consumed
I'm listening for an incoming Azure service bus message. Following the documentation and receiving the message, I parse the message body and then I want to connect to my DB to edit an entry and then save. But I'm getting this error below when trying…

chuckd
- 13,460
- 29
- 152
- 331
1
vote
0 answers
How to fix Cannot access disposed object of Interface
Has anyone been able to fix the issue :
"Cannot access a disposed object.\r\nObject name: 'IService'."} System.Exception {System.ObjectDisposedException}
IService is the interface I'm using. See code block.
internal partial class Controller
{
…

user2775418
- 59
- 8
1
vote
1 answer
"Unhandled" Exception not being caught from inside a try-catch block
I am attempting to run an async output that will last a large amount of time, and then closing the application during execution which causes the textbox to dispose. I thought this would be handled by simply returning in a try-catch statement, but VS…

Plaje
- 65
- 9
1
vote
1 answer
MemoryStream throws ObjectDisposedException when trying to access it in its own using statement
I'm trying to use streams to progressively display a jpeg as it loads. This used to work fine, but this morning I tried running my code and now no images can be loaded because of this error. The relevant code is as follows:
using (WebClient wc = new…

Athied
- 25
- 1
- 5
1
vote
2 answers
My Xamarin forms projects Crashes randomly in Android Device with runtime Exception below
My Xamarin forms projects Crashes randomly in Android Device with runtime Exception "System.ObjectDisposedException: Cannot access a disposed object".
Full Exception details of Exception is provided below.
Xamarin caused by:…

M.Paul D
- 91
- 1
- 6
1
vote
1 answer
ObjectDisposedException in c# database connection class
I am new to C#, I am programming an app in c# that requires the connection of an sqlite database. I thought it would be easiest for me to create my own DBConnection class, which I have given below. The main problem I am having at the moment is with…

Derek Mandl
- 13
- 3
1
vote
1 answer
c# NetworkStream disposed over tcp/ip
I'm hoping someone can tell me why I'm getting an object disposed exception in my tcpListener/tcpClient code.
In the acceptConnections and connectToServer methods I use the keepalive method to tell me when I get disconnected and it works…

Ian Gleeson
- 383
- 3
- 17
1
vote
0 answers
Read is cancelled before stream is disposed, but still throws an exception
I am currently getting an 'ObjectDisposed' exception, and I'm not sure how to resolve it. I have made sure I am checking that the stream is not closed before I begin the read operation:
token.ThrowIfCancellationRequested();
int amount = await…

Andrew Williamson
- 8,299
- 3
- 34
- 62
1
vote
0 answers
How to prevent ObjectDisposedException on an externally provided resource?
I've got the following task which will run occasionally and utilize externally provided resources.
// start receiving the data
receiving = Task.Run(() =>
{
string dataCopy = string.Empty;
string next = string.Empty;
while (true)
{
…

Snoop
- 1,046
- 1
- 13
- 33