TargetInvocationException in asynchronous web service call

by · November 21, 2008

I’ve seen so many solutions around to solve a TargetInvocationException raised by an asynchronous web service call in .NET and they are all but satisfactory. Some go so far to create a worker thread which is overkill and, above all, a clear sign of cargo culting.

The solution is very very simple. The exception is raised if a call fails due to a network problem, and you have accessed the Result properties of the completion event arguments. Simply check if the Error property is null before accessing the Result property (it’s this access which raises the exception).

Filed Under: .NET, Programming

Add a Comment