0

It's me again and I have another problem. Somewhere, I've found following code:

private T DeepDeserialize<T>(string fileName)
    {
        T returnValue;
        using (FileStream str = new FileStream(fileName, FileMode.Open))
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            returnValue = (T)binaryFormatter.Deserialize(str);
        }
        return returnValue;
    }

I've modified some classes today and now, it always throws an error, which could be translated like this: Before completing the analysis was detected ending stream (I don't know the right translation, the error message is in my language, not in English)

I've tried to insert str.Position = 0; between these two lines in using, which I've found somewhere here, but it doesn't help.

Can someone help me to make it work again? I have no ideas what to do...

SoptikHa
  • 437
  • 4
  • 19
  • 1
    if you modified your classes you can not deserialize them from old file anymore, you will have to serialize them first – Oleg Bogdanov Dec 02 '16 at 21:10
  • Oh, thanks! I've forgot to remake my files :-) What a stupid mistake, right? Thanks again. Can I ask you to post this again as answer for this post, so I can mark it as answer? :-) – SoptikHa Dec 02 '16 at 21:14
  • Sure, there is some limit, I have to wait couple of minutes before I can accept – SoptikHa Dec 02 '16 at 21:21

1 Answers1

1

You have changed the binary layout of your files but most likely trying to deserialize old files. This is not gonna work. You have to serialize new versions first.

P.S. If you would consider versioning and custom formatter at early stages, you might be able to deserialize old data with new classes, depending on how drastic was your change

Oleg Bogdanov
  • 1,712
  • 13
  • 19