Giraffe: With Giraffe 3.6.0, BindJsonAsync in task CE yields runtime error message "Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead."

Created on 13 Apr 2019  路  3Comments  路  Source: giraffe-fsharp/Giraffe

In a POST handler task CE, the following code yields the error message in the title of this issue:

let! body = ctx.BindJsonAsync<NewCommentBody>()

However, by instead following the lead of BindXmlAsync's implementation, the following code works perfectly:

let serializer = ctx.GetJsonSerializer()
let! bodyText = ctx.ReadBodyFromRequestAsync()
let body = serializer.Deserialize<NewCommentBody> bodyText;

You can compare the implementations of BindJsonAsync and BindXmlAsync here: https://github.com/giraffe-fsharp/Giraffe/blob/master/src/Giraffe/ModelBinding.fs#L241

bug ready for release

Most helpful comment

I've managed to recreate this, it looks like we would need Json.NET to add a DeserializeAsync entry point (they have async readers already) https://github.com/JamesNK/Newtonsoft.Json/issues/1193

Microsoft are also bringing a new fast and async library for working with JSON which would be a good idea to offer too. I'm happy to work on this when it matures.

All 3 comments

I've managed to recreate this, it looks like we would need Json.NET to add a DeserializeAsync entry point (they have async readers already) https://github.com/JamesNK/Newtonsoft.Json/issues/1193

Microsoft are also bringing a new fast and async library for working with JSON which would be a good idea to offer too. I'm happy to work on this when it matures.

Should not this be working fine with Utf8JsonSerializer ?

Out in 4.0.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nojaf picture nojaf  路  9Comments

alfonsogarciacaro picture alfonsogarciacaro  路  4Comments

padzikm picture padzikm  路  6Comments

graforlock picture graforlock  路  5Comments

Disco-Dave picture Disco-Dave  路  4Comments