Partilhar via


Not Using using() {..}

Yes, the title is a little confusing. Just wanted to make it little interesting that’s all and no other intentions behind it :)

You must have encountered the following error message often while coding WCF,

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

And yes, it does not give any other detail except the above message. I had no clue on what is happening when I got this error the first time. But the solution to it is simple. Just *remove* the ‘using..{}’ block and replace it with a try{}..catch() and it works as expected.

Unless you do so, you would never get the actual exception information that has taken place in the method because, WCF replaces all information detail with the above exception message.

For more information on why this happens, take a look at the following blog post.

http://blog.genom-e.com/CommentView,guid,b9e3019d-0d68-4344-9c7a-407774323d0f.aspx

Happy Coding !!

Comments