Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is this a bug in .Net? I couldn't find something on web to help me. Please help.

I'm writing a B+ Tree and I want to serialize the B+ Tree instances to file for later loading. I've followed the tutorials step by step: making all nedded classes [serializable], and using this code to Serialize the object:

 

FileStream treeFileStream = new FileStream(treeFilePath, FileMode.Create);

BinaryFormatter serializer = new BinaryFormatter();

serializer.Serialize(treeFileStream, this);

 

 

The problem is here when I try to deserialize the object:

 

FileStream treeFileStream = new FileStream(filePath, FileMode.Open);

BinaryFormatter serializer = new BinaryFormatter();

BPlusTree loadedBPlusTree = (BPlusTree)serializer.Deserialize(treeFileStream);

 

It sometimes throw this exception:

String cannot have zero length.

and some other time this one:

Binary stream does not contain a valid BinaryHeader, 123 possible causes, invalid stream or object version change between serialization and deserialization.

 

Thank you.

  • Administrators
Posted (edited)
Any chance you could attach a small test project that exhibits this behaviour? Failing that is this problem occurring between runs of you app or when you try to serialize / de-serialize within a single run? If the latter you may want to check you are closing down all the files when you have finished with them. Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)

I attached the entire solution

 

Any chance you could attach a small test project that exhibits thi behaviour? Failing that is this problem occurring between runs of you app or when you try to serialize / deserialize within a single run? If the latter you may want to check you are closing down all the files when you have finished with them.

I'm sure that there is no problem with the open/close files, Because deserializer is the one that throws the exception not the filestream. Maybe the hierarchy of my BPlusTree is too complicated. But if this is the case shouldn't serializer throw some exception?

I attached the entire solution.

BPlusTree.zip

Edited by PlausiblyDamp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...