0

I'm experiencing a very weird issue running an ASP.NET Web Api application on my development machine.

The code in question throws an HttpResponseException within an ApiController. On a different machine, this code works as expected and will return a 400 Bad Request. On my development machine, this same code breaks and Visual Studio complains (HttpResponseException was unhandled by user code).

Throwing an HttpResponseException within an .net API controller is standard practice so I'd like to continue using this approach (vs. having the controller return an HttpResponseMessage and creating an error response). Has anyone run into this issue before?

Below is the code in question, I've removed all other code and it now just throws the exception.

public class SearchController : ApiController
{
    public IEnumerable<Bill> Get()
    {
        throw new HttpResponseException( HttpStatusCode.BadRequest );
    }
}

This same code behaves correctly on one machine, breaks on another (my development machine). Could there be some weird settings I've accidentally set in Visual Studio to break default behaviour?

2
  • what do you mean by "unhandled"? does it convert itself to 500 status code? Commented Feb 12, 2014 at 8:26
  • By unhandled I mean that Visual Studio will break and pause debugging when it encounters the throw new HttpResponseException line and present the standard exception details dialog with the heading HttpResponseException was unhandled by user code. The response returned to the browser still has a status code of 400 though. Commented Feb 12, 2014 at 19:35

1 Answer 1

1

Yikes, talk about PEBCAK. Turns out I had explicitly instructed Visual Studio to break on these types of exceptions under Debug > Exceptions. Please see attached screenshot. Hope this helps anyone running into a similar issue.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

FWIW I believe this Exceptions dialog is only available in the more expensive versions of Visual Studio. Community Edition, for example, completely lacks the Debug->Exceptions menu option, so you cannot customise this behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.