Link to home
Start Free TrialLog in
Avatar of svemir
svemir

asked on

FileStream and BinaryFormatter

Hello!
I use FileStream to save my project (Calculation) to hard drive. It works fine. Problem is when I change something in Calculation class that it can not read it again because of different number of items in it. What could I do to make old versions readable?

        BinFormatter.Serialize(FStream, actCalcForm.actCalculation)

Thanks!
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

This, I believe, is the inherent problem with serialization, and makes it an unusable form of persistence as far as I am concerned.  Where are you storing this data?  What other information can you give me that would help me make a recommendation?

Bob
Avatar of svemir
svemir

ASKER

Well,
actually it can be stored where ever user want to. One way to solve this problem is to keep old classes a live inside of application and call it when needed. In that case I need to write additional source code to rewrite informations to new class. Usually it is not a problem because most of inherited classes in main class which I serialize are same. Anyway it seams to me less complicated than old fasion storing data.

I hope that you have better idea about my question.

Thank you anyway.
I'm sorry (as I had anything to do with it! :)) but you just can't.

Binary serialization doen't support different versions, only XML.
If you have a choice, serialize the Calculation class to XML instead of binaly.

The problem can be the security, XML is pretty much human readable.
To overcome this you can:
1- If you really need a very good protection, ecrypt the XML file, using DES or TDES implementes on the System.Security.Cryptography namespace.
2- If you just want put some camuflage on the file just don't save the file as *.xml, choose another file extension :)

Alex :p
Avatar of svemir

ASKER

Could you please give some example of serialization to XML because once I try and it doesn't work.
Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial