mbraceproject / FsPickler

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

FsPicker.Serialize() cannot serialize Nullable<_> #7

Closed vasily-kirichenko closed 10 years ago

vasily-kirichenko commented 10 years ago
type My(id: Nullable<int>) = member x.Id = id

let pickler = FsPickler()
let ms = new MemoryStream()
pickler.Serialize (ms, My(Nullable 3))

which results the following error:

System.ArgumentException: GenericArguments[0], 'System.Nullable`1[System.Int32]', on 'FsPickler.Pickler`1[T] Create[T](FsPickler.IPicklerResolver)' violates the constraint of type 'T'. ---> System.Security.VerificationException: Method FsPickler.DotNetPicklers+StructPickler.Create: type argument 'System.Nullable`1[System.Int32]' violates the constraint of type parameter 'T'.
   at System.RuntimeMethodHandle.GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   --- End of inner exception stack trace ---
   at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   at FsPickler.DotNetPicklers.StructPickler.CreateUntyped(Type t, IPicklerResolver resolver)
   at FsPickler.PicklerResolution.lookup@31.Invoke(Type t)
   at FsPickler.DotNetPicklers.ClassPickler.Create[T](IPicklerResolver resolver)
   at FsPickler.Utils.MethodInfo.GuardedInvoke(MethodInfo m, Object instance, Object[] parameters)
   at FsPickler.DotNetPicklers.ClassPickler.CreateUntyped(Type t, IPicklerResolver resolver)
   at FsPickler.PicklerResolution.lookup@31.Invoke(Type t)
   at FsPickler.PicklerCache.FsPickler-IPicklerResolver-Resolve[T]()
   at FsPickler.FsPickler.Serialize[T](Stream stream, T value, FSharpOption`1 streamingContext, FSharpOption`1 encoding, FSharpOption`1 leaveOpen)
   at <StartupCode$FSI_0011>.$FSI_0011.main@()
eiriktsarpalis commented 10 years ago

Fixed in 83fdb3b28ee7b3374d2ab5425aae065a62bbb262