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
URL:
Depends on:
Blocks:
 
Reported: 2016-07-08 23:46 UTC by Casper Bollen
Modified: 2016-07-08 23:46 UTC (History)
1 user (show)

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


Attachments

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

#I __SOURCE_DIRECTORY__
#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


[<DataContract(Name="request")>]
[<CLIMutable>]
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.