Bug 42446 - DataContractSerializer throws NotImplemented exception
Summary: DataContractSerializer throws NotImplemented exception
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 4.4.0 (C7)
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-07-08 23:46 UTC by Casper Bollen
Modified: 2016-07-08 23:46 UTC (History)
1 user (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Casper Bollen 2016-07-08 23:46:25 UTC
This code runs without problem on .net, but crashes when using mono 4.4.1

#r "System.dll"
#r "System.Net.Http.dll"
#r "System.Runtime.Serialization"

open System
open System.Net.Http
open System.IO
open System.Text
open System.Runtime.Serialization
open System.Runtime.Serialization.Json

type Request =
        [<field: DataMember(Name = "act")>]
        Action: string
        [<field: DataMember(Name = "qry")>]
        Query: obj

let fromJson<'T> (json: string) =
    let dcs = DataContractJsonSerializer(typeof<'T>)
    use ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(json))
    (new StreamWriter(ms)).Write(json)
    dcs.ReadObject(ms) :?> 'T

let toJson o =
    let dcs = DataContractJsonSerializer(o.GetType())
    use ms = new MemoryStream()
    dcs.WriteObject(ms, o) 
    ms.Position <- 0L
    (new StreamReader(ms)).ReadToEnd()

{ Action = "Test"; Query = new Object() }
|> toJson
|> printfn "%s"

This is a minimal failing test, just throw it to the fsharpi and compare it with the fsi result.

Note You need to log in before you can comment on or make changes to this bug.