Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: ReadAsMultipartAsync gives "Unexpected end of MIME multipart stream... " with async void web API method [579]

$
0
0
When I have a web API method with a signature like this:

public async void Post()

I get an exception that says:
"Unexpected end of MIME multipart stream. MIME multipart message is not complete."

when reading the multipart data with this line:
await Request.Content.ReadAsMultipartAsync(provider);

However when I change the method into:
public async Task<Boolean> Post()

returning a Task with any type (in this case bool) everything works fine.
Comments: The reason is that when your action just returns "void" then we don't know that the action is still processing the request and so we complete it which leads to the error you see. By returning a Task we can track that the action is still doing things and so we don't continue until it is done. Because it is using Tasks we of course don't block any threads waiting but we have to know when the action is complete. You can also do this (just returning Task and not Task<T>): public async Task Post() Hope this helps, Henrik

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>