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