Why can't I use the AccessDeniedException namespace?

I am getting a message that the namespace cannot be found when I use the below code. Where does AccessDeniedException live?

try { ... } 
catch (SomeKindOfException ex) 
{ 
MessageBox.Show(ex.Message); 
} 
catch (AccessDeniedException ex) 
{ 
//Do something else 
}

      

thank

+1


source to share


2 answers


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.

+1


source


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.



0


source







All Articles