question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing async versions for Bind<T> and BindAndValidate<T>

See original GitHub issue

From version 10.0 Newtonsoft.Json supports async serialization and deserialization from streams using JToken (and derived).

Would be useful to add the async versions for Bind<T> and BindAndValidate<T> extension methods, which will read the request body in a fully async manner:

var model = await req.BindAsync<MyModel>();
await res.Negotiate(model);

If interested I may send a PR.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
jchannoncommented, Jul 16, 2019

Ah good spot! Thanks.

For asp.net core 3 we will probably move to the new json serializer that comes with it

On Tue, 16 Jul 2019 at 10:17, Stephen Pope notifications@github.com wrote:

This seemed the most logical place to put this … I can open up a seperate issue if needed.

I was starting to use Carter (4.2.0) with Netcore 3.0 Preview 6 (3.0.100-preview6-12264).

When trying to call BindAndValidate I get the following error …

System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.StreamReader.ReadBuffer(Span1 userBuffer, Boolean& readToUserBuffer) at System.IO.StreamReader.ReadSpan(Span1 buffer) at System.IO.StreamReader.Read(Char[] buffer, Int32 index, Int32 count) at Newtonsoft.Json.JsonTextReader.ReadData(Boolean append, Int32 charsRequired) at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonReader.ReadAndMoveToContent() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader) at Carter.ModelBinding.BindExtensions.Bind[T](HttpRequest request) at Carter.ModelBinding.BindExtensions.BindAndValidate[T](HttpRequest request)

It seems to relate to this announcement -> aspnet/AspNetCore#7644 https://github.com/aspnet/AspNetCore/issues/7644 … that synchronousIO is disallowed by default in NetCore 3.

Adding :

var syncIOFeature = req.HttpContext.Features.Get<IHttpBodyControlFeature>();

if (syncIOFeature != null) { syncIOFeature.AllowSynchronousIO = true; }

… before calling it solves the issue. But it seems that BindAndValidate method is going to blow up by default from NetCore 3 onwards.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/39?email_source=notifications&email_token=AAAZVJU4WTIQFAXBJYIEXVTP7WGY3A5CNFSM4D7HB4W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2AHS4Q#issuecomment-511736178, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZVJR32VCYGBNDMHJH6CLP7WGY3ANCNFSM4D7HB4WQ .

1reaction
davidfowlcommented, Nov 1, 2017

Memory stream is a bad idea that’s why we don’t do that 🙂.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found