mbraceproject / FsPickler

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

System.MissingMethodException #16

Closed thinkbeforecoding closed 9 years ago

thinkbeforecoding commented 10 years ago

When UnPickling with JsonPickler, it throws a MissingMethodException:

System.MissingMethodException: Method not found: 'Void Newtonsoft.Json.JsonReader.set_SupportMultipleContent(Boolean)

Repro:

#r @"..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll"
#r @"..\packages\FsPickler.0.9.4-alpha\lib\net45\FsPickler.dll"
#r @"..\packages\FsPickler.Json.0.9.4-alpha\lib\net45\FsPickler.Json.dll"

type Cases =
    | This of content:string
    | That of value:int * content:string

open Nessos.FsPickler
let pick = JsonPickler()
let v = pick.PickleToString (This "hello")

let e = pick.UnPickleOfString<Cases> v
eiriktsarpalis commented 10 years ago

Hi, this might have something to do with the fact that Microsoft ships many of its products with older versions Json.Net. To verify that this is true, try doing the following

typeof<Newtonsoft.Json.JsonReader>.Assembly.Location

Mine turned out to be a version 4.5 tucked inside the Visual Studio installation folder. I was able to fix this by manual installing Json.NET before adding FsPickler. Let me know if that helps

thinkbeforecoding commented 10 years ago

Actually the error happens in a tutorial fsx project, put it works when running it with debugger... Seems is more related to assembly linking than to pickler code.

Sorry :ambulance:

eiriktsarpalis commented 10 years ago

This seems to be an issue with FSI. Sending an '#r' directory will not actually load the assembly at that point, so unless you explicitly reference a Json.Net object before you call anything from the pickler, the wrong assembly will be loaded.

This is strange, and extremely annoying.

thinkbeforecoding commented 10 years ago

It works using #I:

#I @"..\packages\Newtonsoft.Json.6.0.3\lib\net45"

I remember reading about it already.. It's better to #I all paths, the just #r assembly names...

brodyberg commented 9 years ago

I just hit this. If it's endemic to the system can we open a bug and while that bug is being evaluated place a note in the examples? The issue makes the examples feel broken.

eiriktsarpalis commented 9 years ago

This issue only affects F# interactive. I'm not sure if it qualifies as a bug, since automatic dependency resolution is really a feature. But you are right, I should update the samples to reflect the need for Json.Net to be explicitly referenced.

brodyberg commented 9 years ago

Much appreciated! I spend a lot of time assuring people they can be quickly successful with F# and related projects. Stuff like this is an important part of making that happen.

eiriktsarpalis commented 9 years ago

I made this addition http://nessos.github.io/FsPickler/tutorial.html#The-core-serialization-API

brodyberg commented 9 years ago

I love it