1
votes

I have a Windsor ASP.NET MVC WebAPI project setup like:

http://nikosbaxevanis.com/2012/07/16/using-the-web-api-dependency-resolver-with-castle-windsor-scoped-lifetime/

Everything works fine when my controller returns an OK status. However, if I try to send an error status, like not NotFound, then I get the following error:

Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope+SerializationReference,Castle.Windsor, Version=3.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc

Here is my controller method:

    // 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);
    }

Notice, if I comment out the line with "resp.Content", then everything works fine.

1

1 Answers

2
votes
throw Request.CreateErrorResponse(HttpStatusCode.NotFound, "My custom message");