Another possibility is that the code being executed doesn't have the required premissions.
In my case, I got this error when using Visual Studio debugger to test a call to a web service. Visual Studio wasn't running as Administrator, which caused this exception.