mbraceproject / FsPickler

A fast multi-format message serializer for .NET
http://mbraceproject.github.io/FsPickler/
MIT License
324 stars 52 forks source link

Pickling something through an FSX session and unpickler in an app #62

Closed isaacabraham closed 8 years ago

isaacabraham commented 8 years ago

If I try to do the above, I get an error such as: -

Nessos.FsPickler.FsPicklerException was unhandled by user code
Message: An exception of type 'Nessos.FsPickler.FsPicklerException' occurred in FsPickler.dll but was not handled in user code
Additional information: Error deserializing object of type 'Microsoft.FSharp.Collections.FSharpList`1[MyNamespace.MyType]'.

Expected pickle of type 'Microsoft.FSharp.Collections.FSharpList`1[MyNamespace.MyType]' but was 'Microsoft.FSharp.Collections.FSharpList`1[FSI_0002.MyNamespace.MyType]'.

Should the FSI_0002 really be there? Is there any way to stop it happening?

eiriktsarpalis commented 8 years ago

Try resetting fsi. It looks like you are serializing an interaction type rather than a library type. On Thu, 27 Aug 2015 at 04:02 Isaac Abraham notifications@github.com wrote:

If I try to do the above, I get an error such as: -

Nessos.FsPickler.FsPicklerException was unhandled by user code Message: An exception of type 'Nessos.FsPickler.FsPicklerException' occurred in FsPickler.dll but was not handled in user code Additional information: Error deserializing object of type 'Microsoft.FSharp.Collections.FSharpList`1[MyNamespace.MyType]'.

Expected pickle of type 'Microsoft.FSharp.Collections.FSharpList1[MyNamespace.MyType]' but was 'Microsoft.FSharp.Collections.FSharpList1[FSI_0002.MyNamespace.MyType]'.

Should the FSI_0002 really be there? Is there any way to stop it happening?

— Reply to this email directly or view it on GitHub https://github.com/nessos/FsPickler/issues/62.

isaacabraham commented 8 years ago

Tried resetting. By "interaction type", I'm #loading the types in to FSI - is that the problem (rather than getting them by a #r)?

krontogiannis commented 8 years ago

Yes, you should #r the compiled assembly that you reference in your app. If you observe F# interactive, after running #load "foo.fs" you will see that it prepends FSI_XXXX in all namespaces declared in foo.fs.

isaacabraham commented 8 years ago

Mmmm, ok. This makes sense. It might be an idea to emit a warning if pickling a type that has FSI_ at the start - I didn't think it would matter.

eiriktsarpalis commented 8 years ago

@isaacabraham It's not inherently impossible to serialize FSI generated types, this is for example one of the things that Vagabond can do.

Should I close this?

isaacabraham commented 8 years ago

Up to you. Like I said, it wasn't obvious to me that using an interaction type wouldn't work in conjunction with a compiled type. Maybe just a warning would be sufficient here or something similar.

eiriktsarpalis commented 8 years ago

It does work. It's just that you need to have the same type definition loaded in the remote process as well, which is not trivial to achieve normally.

isaacabraham commented 8 years ago

Yeah. I was serializing data through FSI and deserializing in an application.

adicirstei commented 7 years ago

It would be nice though to be able to serialize/deserialize in interactive scripts.

eiriktsarpalis commented 7 years ago

@adicirstei you should consider using Vagabond. https://mbraceproject.github.io/Vagabond

adicirstei commented 7 years ago

@eiriktsarpalis I'll give it a try. Currently I am pretty happy with FsPickler. I'm using it to persist neural networks after the training is over. It's just for data.