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

Commented Issue: Web host: exceptions from HttpContent.TryComputeLength are unhandled [1320]

$
0
0
On web host, the code below will always result in the yellow screen of death. (We don't guard calls to content.Headers.ContentLength, which call the user-replacable HttpContent.TryComputeLength and may throw.)

public class WebApiController : ApiController
{
[Route("~/WebApi")]
public IHttpActionResult Get()
{
return new FormatterExceptionResult();
}
}

class FormatterExceptionResult : IHttpActionResult
{
public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
{
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new ExceptionContent();
return Task.FromResult(response);
}
}

class ExceptionContent : HttpContent
{
protected override Task SerializeToStreamAsync(Stream stream, System.Net.TransportContext context)
{
throw new NotSupportedException();
}

protected override bool TryComputeLength(out long length)
{
// Throwing here always results in YSOD (we don't guard calls to this Try method).
throw new NotImplementedException();
}
}

Comments: commit 9751c4e8ca097f1e318d01581dc0be49d512ab7a

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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