-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Controller [FromBody] argument is null if project references "System.Data.SqlClient 4.1.0" #1605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you please include your controller code (ok to omit the method bodies) and some information about what the request looks like? If this is in a public repo, just give us a pointer and we'll take a look. |
@rynowak Here you go sir. The following commit fixes the [FromBody] argument = null issue: To test the API locally you can execute the following request in Fiddler/Postman: Verb + url: POST http://localhost:5001/tasks
|
Thanks, I gave this a try and was able to see what you were seeing. The issue here is that there was a breaking change between the 1.0.0-RC2 and 1.0.0 release to To fix this you can either upgrade your ASP.NET binaries to 1.0.0 or use As far as why this isn't failing in a better way, I'm going to open an issue for this on MVC. The error coming from Kestrel was a |
@rynowak Thanks! I made my project use the rc2 version of System.Data.SqlClient and it indeed worked well for me. It is funny, I saw the error in ModelState while debugging. I was unable to relate this error to a null reference issue I observed. Thank you for opening #4920. I hope improving this code will allow other developers to see their projects following the Fail Fast principle. |
I'm running into something similar. I upgraded from RC2 to Release and a weird error appeared. I post json to a controller method and [FromBody] works fine the first time. But with subsequent calls (that are exactly identical) I get a null value for the [FromBody] argument. It appears to be Kestrel related because it works fine running locally with IISExpress or on our test server under IIS. Ideas? |
@codeConcussion did you look in |
@rynowak Just looked at it. No errors in It could be a completely different issue or just some boneheaded mistake I'm making but it sure seems strange. I'll try to create a slimmed down project from scratch and see if I can recreate it. |
If you can try to create a repro we'd be happy to take a look. |
@rynowak - While creating the repro project I discovered the issue. It's unrelated to this issue even though the end result is the same. We wrote middleware that is reading the I also tried doing Any suggestions on how to correctly read the request body's stream? |
See aspnet/KestrelHttpServer#940. You can work around it by resetting the stream back to the original after the response is written. |
@codeConcussion you can see an example here, https://github.com/aspnet/HttpAbstractions/blob/3e69df87f89601a5ede32c6765b736ab922b8fee/src/Microsoft.AspNetCore.Http/Internal/BufferingHelper.cs but as @davidfowl pointed out, you will currently have a bad time if you don't reset the stream to the original stream when unwinding. @Tratcher did we ship the buffering middleware? |
If my web api project references NuGet package System.Data.SqlClient 4.1.0 then a controller defined in the same project can't retrieve an argument passed in request body. It took me a while to find a diff (see below) that shows what code change introduces the bug in my project.
Here's a controller code I have
Of course I have some service Startup tweaks (e.g. Dependency Injection configuration). I can provide this code too if needed. Is there a way for me to verify there are no errors/exceptions while service is being started? At the moment I test it only on a dev machine.
Could you give me a hint about what I am doing wrong?
The text was updated successfully, but these errors were encountered: