我有一个 Windsor ASP.NET MVC WebAPI 项目设置,例如:
当我的控制器返回 OK 状态时,一切正常。但是,如果我尝试发送错误状态,例如 not NotFound,则会收到以下错误:
Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope+SerializationReference,Castle.Windsor,版本=3.1.0.0,文化=中性,PublicKeyToken=407dd0808d44fbdc
这是我的控制器方法:
// GET api/values
public IEnumerable<string> Get()
{
bool valid = ...;
if (valid)
return new[] {"valid"};
HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound);
resp.Content = new StringContent("My custom message");
throw new HttpResponseException(resp);
}
请注意,如果我用“resp.Content”注释掉该行,那么一切正常。