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
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