FsPickler icon indicating copy to clipboard operation
FsPickler copied to clipboard

Support for pickling code from Reflection.Emit?

Open hsenag opened this issue 3 years ago • 1 comments

Would it be plausible to add support to pickle things produced by System.Reflection.Emit, or is that inherently difficult?

My use case is that for slightly complicated reasons I want to send some code from machine A to B via a quotation, execute part of that code on B and then send a continuation to machine C via FSPickler.

A very simplified example would be

let v = <@ fun x -> x+1 @>

let w : int -> int = FSharp.Quotations.Evaluator.QuotationEvaluator.Evaluate v

let fspickler = MBrace.FsPickler.FsPickler.CreateBinarySerializer()
fspickler.Pickle(w)

which currently fails as expected because System.Reflection.Emit.DynamicMethod+RTDynamicMethod is not serializable by FsPickler:

 Unhandled exception. MBrace.FsPickler.FsPicklerException: Error serializing object of type 'Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32]'.
---> MBrace.FsPickler.NonSerializableTypeException: Type 'System.Reflection.Emit.DynamicMethod+RTDynamicMethod' is not serializable: global method 'Int32 lambda_method(System.Runtime.CompilerServices.Closure, Microsoft.FSharp.Core.Unit, Int32)' in assembly 'Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

I'm aware of Vagabond but currently it only advertises support for .NET Core 3.1 and I also need to support .NET Framework 4. Would I be better off trying to get Vagabond to support .NET Standard?

hsenag avatar Jun 21 '21 07:06 hsenag

I'm aware of Vagabond but currently it only advertises support for .NET Core 3.1 and I also need to support .NET Framework 4.

I randomly saw this, and just wanted to mention that this commit removed .NET FX support from Vagabond.

You might just be able to use an older version from NuGet.

0x53A avatar Aug 31 '21 12:08 0x53A