为什么我不能使用'AccessDeniedException'命名空间?

时间:2021-07-04 06:52:41

I get the message that the namespace can't be found when I use the code below. Where does the AccessDeniedException live?

当我使用下面的代码时,我收到了无法找到命名空间的消息。 AccessDeniedException在哪里?

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

Thanks

2 个解决方案

#1


1  

I don't think that's the exception you're looking for. The only one with this name (that I can find) is in a Sharepoint namespace. Try attaching the debugger and seeing exactly what the type of the thrown exception is.

我不认为这是你正在寻找的例外。唯一具有此名称的(我可以找到)位于Sharepoint名称空间中。尝试附加调试器并确切了解抛出的异常的类型。

The type of the exception is going to vary depending on your context. So for example, if it's an "access denied" when trying to open a file, it could be a FileLoadException, or something similar. If it's encountered because of Code Access Security, it will be SecurityException. And so on.

异常的类型将根据您的上下文而有所不同。因此,例如,如果在尝试打开文件时它是“访问被拒绝”,则可能是FileLoadException或类似的东西。如果由于代码访问安全性而遇到它,它将是SecurityException。等等。

#2


0  

You may need to give the full namespace on the exception, or have a using statement at the top of your code file so .NET knows where to find the exception you're talking about. If that doesn't work, maybe you need to add the DLL that contains that exception to the "REFERENCES" list in your project.

您可能需要在异常上提供完整的命名空间,或者在代码文件的顶部有一个using语句,以便.NET知道在哪里找到您正在讨论的异常。如果这不起作用,可能需要将包含该异常的DLL添加到项目的“REFERENCES”列表中。

#1


1  

I don't think that's the exception you're looking for. The only one with this name (that I can find) is in a Sharepoint namespace. Try attaching the debugger and seeing exactly what the type of the thrown exception is.

我不认为这是你正在寻找的例外。唯一具有此名称的(我可以找到)位于Sharepoint名称空间中。尝试附加调试器并确切了解抛出的异常的类型。

The type of the exception is going to vary depending on your context. So for example, if it's an "access denied" when trying to open a file, it could be a FileLoadException, or something similar. If it's encountered because of Code Access Security, it will be SecurityException. And so on.

异常的类型将根据您的上下文而有所不同。因此,例如,如果在尝试打开文件时它是“访问被拒绝”,则可能是FileLoadException或类似的东西。如果由于代码访问安全性而遇到它,它将是SecurityException。等等。

#2


0  

You may need to give the full namespace on the exception, or have a using statement at the top of your code file so .NET knows where to find the exception you're talking about. If that doesn't work, maybe you need to add the DLL that contains that exception to the "REFERENCES" list in your project.

您可能需要在异常上提供完整的命名空间,或者在代码文件的顶部有一个using语句,以便.NET知道在哪里找到您正在讨论的异常。如果这不起作用,可能需要将包含该异常的DLL添加到项目的“REFERENCES”列表中。