Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebFaultException not handled in user code

I am using WCF REST Service (4.0) to expose JSON API ..but not getting my WebFaultException to work.

I have following in my method:

        if (!int.TryParse(Id, out idValue))
        {
            throw new WebFaultException<string>(string.Format(WebExceptionMessages.NotIntegerAsParameter),
                                                HttpStatusCode.BadRequest);
        }

and when i try to call the service from fiddler i always receive the same error message:

Error when debugged

I have been trying to search for a solution for some time now...please help.

like image 476
Ingimar Andresson Avatar asked Apr 19 '26 21:04

Ingimar Andresson


1 Answers

The WebFaultException is working properly - the error message in Visual Studio is just telling you that it wasn't handled - that's the expected behavior. Visual Studio debugger will tell you it's unhandled since you didn't trap the error via try/catch. See related MSDN blog regarding WebFaultException usage.

like image 114
SliverNinja - MSFT Avatar answered Apr 22 '26 12:04

SliverNinja - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!