Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 17, 2012 10:23 PM by Kiran Challa
Feb 17, 2012 09:08 PM|LINK
public Task<HttpResponseMessage> SomeApiMethod()
return Request.Content.ReadAsStreamAsync().ContinueWith(s =>
var doc = XDocument.Load(s.Result);
Throws: Cannot access a closed Stream, but ReadAsString() works fine.
Feb 17, 2012 09:11 PM|LINK
That sounds like a bug. It shouldn't have closed if it hasn't been read.
Feb 17, 2012 10:23 PM|LINK
It would be helpful if you could past the entire Action method here. I say this because, a similar scenario like yours works for me:
public Task<string> TestActionReadingAsStream()
return Request.Content.ReadAsStreamAsync().ContinueWith<string>(tsk =>
string value = null;
using (StreamReader reader = new StreamReader(tsk.Result))
value = reader.ReadToEnd();