Save example

Feb 15, 2011 at 4:43 PM

I wonder if anyone had an example of using or describing th e Save method of the engine.  I am trying to do

            FileStream serializeStream = new FileStream("script.dat", FileMode.Create);

            engine.Save(serializeStream);

but I keep getting an exception that ExecutionVisitor is not serializable...

 

Type 'Jint.ExecutionVisitor+ResultInfo' in Assembly 'Jint, Version=1.1.4059.16513, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Any suggestions here?

 

Coordinator
Feb 15, 2011 at 5:30 PM

Can you try to add a [Serializable] attribute on the ResultInfo class ?

Feb 15, 2011 at 5:55 PM

I did and that moved me to Jint.Marshaller which I also marked as serializable and it is stuck on Jint.PropertyBags.MiniCachedPropertyBag…

Should I continue down this path?

Jeff

From: sebastienros [email removed]
Sent: Tuesday, February 15, 2011 1:30 PM
To: jeff@therosenthalwebsite.com
Subject: Re: Save example [jint:246146]

From: sebastienros

Can you try to add a [Serializable] attribute on the ResultInfo class ?

Developer
Feb 15, 2011 at 6:55 PM

Currently serialization is broken, like multithreading it needs some principal questions to be answered:

What we are expecting from saving and restoring a state? JintEngine is only a state of 'global' object and some service objects like a marshaller and ExecutionVisitor.

Saving a marshaller is not a very good idea since its state consists of some internal cache tables only, futhermore marshallers are sharing some data (currently genarated IL code).

But if we look at 'global' object we'll see that it can hold any object and apparentaly non-serializable.

Therefore it's not trivial to save and restore a JintEngine state.

But if we want to save a state, run some script and then return to the original state we can use some other techniques such as snapshots or clonning.

Feb 17, 2011 at 7:16 AM

I expected that serialization will allow me to clone the engine state, so basically it could be a clone/snapshot function without byte stream serialization.  Can't think of any really useful scenario where we would need to persist and restore the serialized engine state (and apart from that, we don't control what the state contains and if it's serializable at all so there's no way to make it work in every case).