Why can't I use the AccessDeniedException namespace?
I don't think this is the exception you are looking for. The only one with this name (which I can find) is in the Sharepoint namespace. Try attaching a debugger and see what the type of exception thrown is.
The type of exception will vary depending on your context. For example, if access is denied when trying to open a file, it might be a FileLoadException or something similar. If it has to do with passcode protection, it will be a SecurityException. Etc.
source to share
Perhaps you need to specify the full namespace in the exception, or use a using statement at the top of your code file so that .NET knows where to find the exception you are talking about. If that doesn't work, you might need to add the DLL containing this exception to the "REFERENCES" list in your project.
source to share