Skip to content

Added sample Code for an issue#26374

Closed
sammychinedu2ky wants to merge 12 commits into
dotnet:mainfrom
sammychinedu2ky:main
Closed

Added sample Code for an issue#26374
sammychinedu2ky wants to merge 12 commits into
dotnet:mainfrom
sammychinedu2ky:main

Conversation

@sammychinedu2ky
Copy link
Copy Markdown
Contributor

@sammychinedu2ky sammychinedu2ky commented Jul 9, 2022

Added Sample Code for #26346 and #26370

@Rick-Anderson EDIT:
Fixes #26346 Fixes #26370

'the conditional statement should come after 
```
_array = _c.GetSection("array").Get<ArrayExample>();

```
The removal of the early initialization avoids the problem of having empty indexes when the controller processes the request
@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

@Rick-Anderson @RickAndMSFT

@Rick-Anderson Rick-Anderson self-assigned this Jul 9, 2022
@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

sammychinedu2ky commented Jul 12, 2022

Added sample code for another issue #26370
@Rick-Anderson and @wadepickett

@Rick-Anderson
Copy link
Copy Markdown
Contributor

@sammychinedu2ky testing the sample, it's great. Works perfect from Postman but from curl I get the following error:
c:>curl --request POST https://localhost:54535/register --header 'Content-Type: application/json' --data-raw '{ "Name":"Samson", "Age": 23, "Country":"Nigeria" }'
registeredcurl: (6) Could not resolve host: application
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: 23,
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 1:
}'
^

And the output window shows

info: PipeStreamToBackgroundQueue[0]
Reading the stream from the request body.
fail: BackGroundQueueService.BackGroundQueue[0]
''' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.

BTW, Reading the stream from the request body. comes from logging I put in program.cs.

@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

ok, would try it out again. I'm making a new pull request soon on this

@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

you'll also have to reset the position of the stream after reading from the body. Because it was designed to be read once.

@Rick-Anderson
Copy link
Copy Markdown
Contributor

Rick-Anderson commented Jul 15, 2022

This fixes it
curl --request POST https://localhost:54535/register --header "Content-Type: application/json" --data-raw "{ \"Name\":\"Samson\", \"Age\": 23, \"Country\":\"Nigeria\" }"

Can't use single quotes, must be double quotes. You must be on a macboook

@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

ooh, Thanks would use this in the pull request. I'm on windows 😅

@Rick-Anderson
Copy link
Copy Markdown
Contributor

Ha, what shell are you running curl from? I'm running it from a developer command prompt.

@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

I used GitBash to try out the curl. Your update also worked there as well. So I just stuck to the fix you made since it also worked there.

@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

Made a new pull request here #26437

@Rick-Anderson
Copy link
Copy Markdown
Contributor

image

@Rick-Anderson
Copy link
Copy Markdown
Contributor

I just added them and it seems to be working. I'll look at the code now.

@sammychinedu2ky
Copy link
Copy Markdown
Contributor Author

Opened a pull request for this last one here #26438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET 7: Code sample for Microsoft.AspNetCore.Http.TypedResults .NET 7: Add sample for Minimal API Bind the request body as a Stream or PipeReader

2 participants