This project has moved and is read-only. For the latest updates, please go here.

How to serialize?

Jun 24, 2014 at 11:41 AM
Edited Jun 24, 2014 at 11:56 AM
Hello,

I am trying to serialize this function:
 var func = TermBuilder.Power(2 * -x, TermBuilder.Exp(-x * -2)) * TermBuilder.Exp(-x * y * (-2)) - x * y * y * (-y);
with this code:
            // serialize the func
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, func);
            stream.Close();

            func = null;


            // deserialize the func
            stream = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
            func = (Term)formatter.Deserialize(stream);
            stream.Close();


            Console.WriteLine("done");
            Console.ReadKey();
and i can not because TermPower is not Serializable.
After adding the Serializable attribute it serializes and deserializes, but the rest of execution fails at compilation.

Is there anything i am doing wrong?

P.S. My serialization/deserialoization code is from here: http://msdn.microsoft.com/en-us/library/4abbf6k0%28v=vs.110%29.aspx

Thanks!
Jun 30, 2014 at 12:43 PM
Well, this is obviously a bug.
You can download the library's source code, fix it and build it.

I will fix it in a later release, when I make more time to develop the library. If you wish to do it, please say so. I will give you permissions to develop.
Jun 30, 2014 at 12:49 PM
I have figured that out.

The problem actually is that the Variables created after deserialization are not the ones that were used when the term was created.

eg.: if X is the variable before the serialization, then Variable deserialized_X != X.

If i remember correctly, this happens during compilation of the term, when a dict is used. I can't remember the exact piece of code right now.