#How to diagnose a ObjectDisposedException?

1 messages · Page 1 of 1 (latest)

fallow topaz
#

I keep getting a ObjectDisposedException for seemingly no reason, the dispose method is never called but the error is consistantly there. what should i do to diagnose this? thx

#

i can post the code of someone wants but its a long ass file

jaunty crater
#

Is there a using statement somewhere in your code?

#

Aside from the references at the top I mean

#

Like a FileStream or something

fallow topaz
#

yeah, heres what i got for those

#
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using ICSharpCode.SharpZipLib.Zip;
using uSource.Formats.Source.VTF;
using uSource.MathLib;
using UnityEngine;
#

should i check in all of those for anything calling dispose?

jaunty crater
#

Yeah I'm talking about within the class itself. It's usually used in writing to a file stream or sometimes UI

fallow topaz
#
static void LoadStaticProps()
        {
            Debug.Log("File Reader Obj: " + BSPFileReader);
            Debug.Log("Base Stream: " + BSPFileReader.BaseStream);
            Debug.Log("Lumps: " + BSP_Header.Lumps[35]);
            BSPFileReader.BaseStream.Seek(BSP_Header.Lumps[35].FileOfs, SeekOrigin.Begin);
            Int32 GameLumpCount = BSPFileReader.ReadInt32();

            dgamelump_t[] BSP_GameLump = new dgamelump_t[GameLumpCount];
            BSPFileReader.ReadArray(ref BSP_GameLump);

            for (Int32 i = 0; i < GameLumpCount; i++)
            {``` heres part of it, i dont wanna clog the chat up lol
jaunty crater
#

So like if you create an object like FileStream or otherwise, call .Close() on it, then try to access it again

fallow topaz
#

the error is on BSPFileReader.BaseStream.Seek

#

CanSeek also returns false

jaunty crater
#

BSP? I'm not familiar. Can't find docs on it either.

In any case BSPFileReader or BSPFileReader.BaseStream must implement IDisposable - so it automatically disposes itself when it thinks you're done with it.

fallow topaz
#

bsp is a map format for valve games, its a pita

jaunty crater
#

You can try to put any code that uses it inside a using statement.

#

In any case if you have docs for that code I'd suggest referencing the page for BaseStream to see if any examples are included

fallow topaz
#

what confuses me even more is the stacktrace, it wont even give me the object name, only this:

#

ObjectDisposedException: Cannot access a disposed object.
Object name: 'Stream has been closed'.

#

i found the docs for basestream and read thru it but i still dont get why its not workin lol

jaunty crater
#

Try calling BSPFileReader.BaseStream.Open(); before you use it for anything else. Shot in the dark.

#

Then .Close() when you're done with it

fallow topaz
#

theres no .Open :(

jaunty crater
#

Hmmm

#

This is really messing with me lol:

fallow topaz
#

i can send the github repo i got it from if u want

jaunty crater
#

Might help.

fallow topaz
jaunty crater
#

Do you have something like uReader BSPFileReader = new uReader(new MemoryStream())?