The exception that is thrown when an operation is performed on a disposed object.
Questions tagged [objectdisposedexception]
190 questions
2
votes
3 answers
Reader.IsConsumed is false but object was disposed
I'm using QueryMultiple which returns a GridReader.
Since I don't know how much data I'm gonna read, I'm looping over the reader with the stop condition of IsConsumed:
using (var reader = conn.QueryMultiple(mySql)) {
while(!reader.IsConsumed) {
…

Mugen
- 8,301
- 10
- 62
- 140
2
votes
1 answer
How can I write an fprintfn function that opens, appends, closes the file on each write, without getting an ObjectDisposedException?
TL;DR: how to write a function like fprintfn that accesses and closes a file and behaves similar to printf family of functions, but won't throw an ObjectDisposedException on multiple arguments?
As a convenience embedded function, I found myself…

Abel
- 56,041
- 24
- 146
- 247
2
votes
2 answers
How to correctly dispose of asyc NetworkStream
I'm attempting to dispose of a NetworkStream after it's finished writing. I've tried wrapping the stream in a using() like so:
using (NetworkStream stream = client.GetStream())
{
foreach (byte[] command in fadeSceneOut)
{
if…

DGibbs
- 14,316
- 7
- 44
- 83
2
votes
3 answers
GhostScript Rasterizer Out of Memory Exception
I am working with a 32-bit Console Application that operates as a background processor. The part I am working on uses GhostScript to Perform OCR on PDFs. Each page of a PDF is rendered to a PNG image in a temp folder which the OCR Reader then reads.…

Aaron
- 41
- 1
- 8
2
votes
1 answer
Catching an ObjectDisposedException thrown at UDPClient.EndReceive
I'm using an async callback in a windows service to receive UDP data broadcast on a network.
The callback uses the UDPClient.EndReceive() method to end the pending async receive. During the service OnStop() method I UDPClient.Close() the UDP…

khargoosh
- 1,450
- 15
- 40
2
votes
1 answer
ObjectDisposedException when creating user
I'm getting an error when I try to create a user. I got it at line 15 in the following code.
1 public async void AddOrganisationAdmin()
2 {
3
4 String OrganisationName = Request["OrganisationName"];
5 …

Gert Kommer
- 1,163
- 2
- 22
- 49
2
votes
3 answers
Properly Avoid ObjectDisposedException
I ran into an issue where an ObjectDisposedException is being thrown roughly 50% of the time. The code within the try (within the finally) below, is causing the exception. I'm not sure how to handle this. I could just eat the exception, like shown…

Bob Horn
- 33,387
- 34
- 113
- 219
2
votes
1 answer
Cannot determine the cause of System.ObjectDisposedException during application shutdown
I am stuck in a debugging scenario and I need help understanding how I might get more information about what is happening to my application.
The exception is thrown when I close the main form, seemingly during the last bit of processing prior to…

DonBoitnott
- 10,787
- 6
- 49
- 68
2
votes
1 answer
Unexpected "Cannot access a disposed object" in clean up method
I am facing a puzzling disposed object issue when I shut down my WPF application. If you spot any mistakes in my logic please point them out.
I have a ColorManager class with update() method, as shown below.
public void Update(ColorImageFrame…

ikel
- 518
- 2
- 6
- 27
2
votes
0 answers
System.ObjectDisposedException after changing from WPF project to WinForms context
The application was started from an empty C# project, output type set to "Windows App":
using System.Windows.Forms;
static class Program
{
static System.Windows.Forms.NotifyIcon notifyIcon;
static System.Drawing.Icon LockedIcon =…

Joe
- 2,496
- 1
- 22
- 30
2
votes
1 answer
Object Instance has been disposed (EF)
I'm having some problems with retrieving my Project entity in the EntityFramework. It keeps giving me the Objest instance has been disposed error.
I've got 2 instances, as seen in the image below.
And the following code gives me the error:
…

Mittchel
- 1,896
- 3
- 19
- 37
2
votes
2 answers
In vb.net, how do you force-exit an application and stifle error messages?
I want the user to simply be able to exit my application. However, for some reason, code which I have on a time delay, controlled by a stopwatch, is still trying to execute. I do not care if it tries to do so or not, but I want to stop the error and…

Cyclone
- 17,939
- 45
- 124
- 193
2
votes
1 answer
System.ObjectDisposedException Error on C# v4.0
I implemented this code:
C# Processing Fixed Width Files
But since my work PC runs Windows XP I had to save the program using C# v4.0. Unfortunately the following code:
static string filePath = "";
public Main()
{
…

hshah
- 842
- 4
- 14
- 35
1
vote
1 answer
LINQ to SQL, override dispose
I am creating a LINQ to SQL DataContext by passing it an already open connection. This works, except I'm now leaking connections everywhere because although I dispose the DataContext when I'm finished, the connection never gets closed. I understand…

TheNextman
- 12,428
- 2
- 36
- 75
1
vote
2 answers
object disposed exception
Ok guys there is this sudden problem in my code which didn't appear before..
public void StartUdpListener(Object state)
{
/* sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
…

Avik
- 2,097
- 7
- 24
- 30