✅ ObjectDisposedException without explicit trace
Hello, I'm getting exception at different moment, but I don't really understand what is happening.
The stacktrace does not target any lines of my program, how can I find where the issue is ?
Thanks !
34 Replies
It's a .NET 6.0 console app
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
That is the weird part, it crashes at different moment, it's not easy to show. I'll try to crash it again to show
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
It was the SafeHandle.cs file, it's a Microsoft one
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
The exception is thrown here:
(but that is not my code)
Oh I think I got it
I try to open a file that might by already opened by another program
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
The fact is that I didn't know where the execution was stopped, it's a big program, and there was no indication (nothing in the stacktrace) to say "it stopped here in your code"
but anyway, thanks for your help !
That is not solve, the exception was thrown again, I don't know why !
To explain: I develop a game mode for a multiplayer game, I try to make a NPC script. I thought it was crashing because the NPC needs a file and I didn't put a try catch on the file reader.
Now the same exception is thrown before the file reading, that is a nonsense
It seems to have thrown the exception here this time:
are you using multithreading in any way
in particular are you trying to work with the same file from multiple threads or something
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
I'm not really sure if I use multithreading, I use a wrapper (originally the multiplayer game modes are scripted in C++, and I use a wrapper to create a .dll that is used by the server)
I don't know exactly how it works, but it worked well for a long time, I might be doing something wrong
what do you mean by car ?
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Yes maybe, but how can I see what var is causing the issue ?
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
There are a lot of .Dispose(), but usually the exception is thrown on the line where I try to access the variable. Example:
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
I don't really know what is a disposed object, I understand I can use it to delete objects in the game. I haven't find a way to make a disposed object usable again, so I just recreate it again with the
new
statementUnknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Ok, I have understood that, and I think I have not make that in my code (or by mistake maybe)
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
But, what object is Disposed ? How can I see that ? the exception seems to be thrown at different moment
Good to know !
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Oh I think I found the issue
I got the Exception when I modify the code by Hot Reload
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
I never had this issue before, but it sounds like Visual Studio dispose my object
It works all the time, but not here, strange
My code takes about 30 seconds to start, and I have to login to the server etc, ... so hot reload is a real time saver
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Yes, but I use it for months, maybe years without issues !
I don't understand why, in this particular script, the hot reload does not work correctly
I've updated Visual Studio, I'll let you know if the issue happens again
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
yes, debugging async code is difficult. the stack trace indicates that you are writing asynchronously to a synchronous file handle. then, once the I/O operation executes, it is discovered that you closed the handle
it queues the I/O operation to the thread pool, which is why the stack is not helpful
if you want to figure out what the issue is, you can start by setting a breakpoint in FileStream.Dispose(bool) probably...
I worked at least 2 hours with the newest version of Visual Studio, it seems to be fixed.
Thanks for your help !