1

我正在使用 ClearScript 编译一些 JavaScript,然后我想将其序列化以将其存储在 SQL 中。但是它被标记为不可序列化,我该怎么办?

V8ScriptEngine engine = new V8ScriptEngine();
V8Script compiled = engine.Compile("var a = 'test'");
using (MemoryStream ms = new MemoryStream())
{
    new BinaryFormatter().Serialize(ms, compiled);
    string compiledString = Convert.ToBase64String(ms.ToArray());
}

我收到此错误:

Additional information: Type 'Microsoft.ClearScript.V8.V8ScriptImpl' in Assembly 'ClearScriptV8-32, Version=5.4.6.0, Culture=neutral, PublicKeyToken=935d0c957da47c73' is not marked as serializable.
4

1 回答 1

3

V8 编译脚本与创建它的隔离实例相关联,因此序列化它是没有意义的。您不能在不同的进程中重用它,甚至不能在同一进程中使用另一个隔离。这里这里有更多信息。

于 2016-09-21T11:26:03.690 回答