我如何序列化编译V8Script在Clearscript



我使用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.

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

最新更新