- Home /
EndOfStreamException : Failed to read past end of stream
[Serializable]
class LevelData
{
public Dictionary<Vector2, Level> levelButtonData;
}
Alright. I have this class I'm trying to deserialize using BinaryFormatter. It was fine yesterday, I didn't get any exceptions or anything. I could simply serialize and and deserialize my class untill today I wanted to try again. It gave that exception I typed in the title section. And this line is the one that causes that exception:
LevelData lvlData = (LevelData)formatter.Deserialize(file);
I haven't touched anything since yesterday. That's the weird thing.
Answer by Nick4 · Jul 10, 2014 at 09:03 PM
That's what happens when you deserialize a different file :)
Can you explain a little bit more ? A got the same problem and keep struggling with this error message. Here the class i want to serialize (in fact I serialize a list of this class instances).
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Action {
string objective; //position or target
string target;
string script;
Vector2 position;
public Action(string objective, string target)
{
this.objective = objective;
this.target = target;
}
public Action(string objective, Vector2 position)
{
this.objective = objective;
this.position = position;
}
public Vector2 getPosition()
{
return this.position;
}
}
You shouldn't answer a question with another question, use comment section ins$$anonymous$$d :) Well I don't exactly know if it's the same case for you but it looks like you're trying to serialize Vector2 with .net's serializable which is not acceptable 'cuz type Vector2 isn't serializable itself. You can always create your own Vector2 class which would only have 2 variables (x and y) and serialize that.
Thanks for the explanation. I tried to serialize a class with a vector3 attribute, and that's why it didn't work.
Your answer
Follow this Question
Related Questions
EndOfStreamException : Failed to read past end of stream 1 Answer
Using BinaryFormatter for deserialization - ArgumentException: method argument length mismatch 0 Answers
Saving game data: BinaryFormatter vs SoapFormatter 0 Answers
Android IL2CPP bulid crash MemoryStream deserialization 0 Answers
Serialization from WinForms to Unity 1 Answer