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:
[HttpPost]
public Task<string> TestActionReadingAsStream()
{
return Request.Content.ReadAsStreamAsync().ContinueWith<string>(tsk =>
{
string value = null;
using (StreamReader reader = new StreamReader(tsk.Result))
{
value = reader.ReadToEnd();
}
return value;
});
}
chrisortman
Member
38 Points
23 Posts
Re: Passing XDocument as message content
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.
panesofglass
Member
730 Points
237 Posts
Re: Passing XDocument as message content
Feb 17, 2012 09:11 PM|LINK
That sounds like a bug. It shouldn't have closed if it hasn't been read.
Kiran Challa
Participant
1442 Points
281 Posts
Microsoft
Re: Passing XDocument as message content
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: [HttpPost] public Task<string> TestActionReadingAsStream() { return Request.Content.ReadAsStreamAsync().ContinueWith<string>(tsk => { string value = null; using (StreamReader reader = new StreamReader(tsk.Result)) { value = reader.ReadToEnd(); } return value; }); }Kiran Challa