C
C#8mo ago
LDami

✅ 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 !
No description
34 Replies
LDami
LDamiOP8mo ago
It's a .NET 6.0 console app
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
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
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX8mo ago
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!
LDami
LDamiOP8mo ago
It was the SafeHandle.cs file, it's a Microsoft one
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
The exception is thrown here: (but that is not my code)
No description
LDami
LDamiOP8mo ago
Oh I think I got it I try to open a file that might by already opened by another program
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
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
LDami
LDamiOP8mo ago
It seems to have thrown the exception here this time:
No description
Becquerel
Becquerel8mo ago
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
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
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
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
Yes maybe, but how can I see what var is causing the issue ?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
There are a lot of .Dispose(), but usually the exception is thrown on the line where I try to access the variable. Example:
Vehicle veh = new();
veh.Dispose();
TeleportPlayerTo(veh.Position); // Exception should be thrown here
Vehicle veh = new();
veh.Dispose();
TeleportPlayerTo(veh.Position); // Exception should be thrown here
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
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 statement
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
Ok, I have understood that, and I think I have not make that in my code (or by mistake maybe)
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
But, what object is Disposed ? How can I see that ? the exception seems to be thrown at different moment Good to know !
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
Oh I think I found the issue I got the Exception when I modify the code by Hot Reload
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
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
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
LDami
LDamiOP8mo ago
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
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
reflectronic
reflectronic8mo ago
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...
LDami
LDamiOP8mo ago
I worked at least 2 hours with the newest version of Visual Studio, it seems to be fixed. Thanks for your help !
Want results from more Discord servers?
Add your server