PathTooLongException PathTooLongException PathTooLongException PathTooLongException Class

定义

当路径名或完全限定的文件名长度超过系统定义的最大长度时引发的异常。The exception that is thrown when a path or fully qualified file name is longer than the system-defined maximum length.

public ref class PathTooLongException : System::IO::IOException
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class PathTooLongException : System.IO.IOException
type PathTooLongException = class
    inherit IOException
Public Class PathTooLongException
Inherits IOException
继承
属性

注解

如果你的代码FileIOPermissionAttribute.PathDiscovery没有权限, 则此异常的错误消息可能只包含文件或目录名称, 而不是完整路径。If your code does not have FileIOPermissionAttribute.PathDiscovery permission, the error message for this exception may contain only file or directory names instead of full paths.

在之前.NET Framework 4.6.2.NET Framework 4.6.2的 .NET Framework 版本下运行的应用程序中, 完整路径不得超过260个字符, 以便保持与 Windows 操作系统的兼容性。In apps that run under versions of the .NET Framework prior to the .NET Framework 4.6.2.NET Framework 4.6.2, full paths must not exceed 260 characters to maintain compatibility with Windows operating systems. 超过260个字符的任何路径都将PathTooLongException自动引发。Any path in excess of 260 characters automatically throws a PathTooLongException. 有关此限制的详细信息, 请参阅 BCL 团队博客中的 .NET 中的条目长路径For more information about this restriction, see the entry Long Paths in .NET in the BCL Team blog.

备注

Windows 应用商店应用可移植类库中未包含此异常, 但它由某些成员引发。This exception is not included in .NET for Windows Store apps or the Portable Class Library, but it is thrown by some members that are. 若要在这种情况下捕获异常, catch请编写一个IOException句柄来处理。To catch the exception in that case, write a catch statement that handles an IOException instead.

从在下.NET Framework 4.6.2.NET Framework 4.6.2运行的应用开始, .NET Framework 支持超过 260 (或MAX_PATH) 个字符的长路径。Starting with apps running under the .NET Framework 4.6.2.NET Framework 4.6.2, the .NET Framework supports long paths in excess of 260 (or MAX_PATH) characters. 引发PathTooLongException异常的条件取决于应用所面向 .NET Framework 的版本:The conditions under which a PathTooLongException exception are thrown depend on the version of the .NET Framework that an app targets:

面向及更高.NET Framework 4.6.2.NET Framework 4.6.2版本的应用Apps that target the .NET Framework 4.6.2.NET Framework 4.6.2 and later versions
默认情况下支持长路径。Long paths are supported by default. PathTooLongException在以下情况下, 运行时将引发:The runtime throws a PathTooLongException under the following conditions:

  • 操作系统返回 COR_E_PATHTOOLONG 或其等同项。The operating system returns COR_E_PATHTOOLONG or its equivalent.

  • 路径的长度超过Int16.MaxValue (32767) 个字符。The length of the path exceeds Int16.MaxValue (32,767) characters.

面向和更早.NET Framework 4.6.1.NET Framework 4.6.1版本的应用程序Apps that target the .NET Framework 4.6.1.NET Framework 4.6.1 and earlier versions
默认情况下, 长路径处于禁用状态, 并且保持旧行为。Long paths are disabled by default, and the legacy behavior is maintained. PathTooLongException只要路径超过260个字符, 运行时就会引发。The runtime throws a PathTooLongException whenever a path exceeds 260 characters.

如果不需要这样做, 则面向.NET Framework 4.6.1.NET Framework 4.6.1和更早版本但在下运行的.NET Framework 4.6.2.NET Framework 4.6.2应用程序可以通过在应用程序配置文件的 <运行时 >元素中包含以下设置来实现长路径支持:If this is undesirable, apps that target the .NET Framework 4.6.1.NET Framework 4.6.1 and earlier but run under the .NET Framework 4.6.2.NET Framework 4.6.2 can enable long path support by including the following setting in the <runtime> element of the application configuration file:

  
<runtime>   
   <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false" />   
</runtime>  
  

PathTooLongException使用具有值COR_E_PATHTOOLONG0x800700CE 的 HRESULT。PathTooLongException uses the HRESULT COR_E_PATHTOOLONG, which has the value 0x800700CE.

构造函数

PathTooLongException() PathTooLongException() PathTooLongException() PathTooLongException()

初始化 PathTooLongException 类的新实例,使其 HRESULT 设置为 COR_E_PATHTOOLONG。Initializes a new instance of the PathTooLongException class with its HRESULT set to COR_E_PATHTOOLONG.

PathTooLongException(SerializationInfo, StreamingContext) PathTooLongException(SerializationInfo, StreamingContext) PathTooLongException(SerializationInfo, StreamingContext) PathTooLongException(SerializationInfo, StreamingContext)

用指定的序列化和上下文信息初始化 PathTooLongException 类的新实例。Initializes a new instance of the PathTooLongException class with the specified serialization and context information.

PathTooLongException(String) PathTooLongException(String) PathTooLongException(String) PathTooLongException(String)

初始化 PathTooLongException 类的新实例,使其消息字符串设置为 message,而其 HRESULT 设置为 COR_E_PATHTOOLONG。Initializes a new instance of the PathTooLongException class with its message string set to message and its HRESULT set to COR_E_PATHTOOLONG.

PathTooLongException(String, Exception) PathTooLongException(String, Exception) PathTooLongException(String, Exception) PathTooLongException(String, Exception)

使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 PathTooLongException 类的新实例。Initializes a new instance of the PathTooLongException class with a specified error message and a reference to the inner exception that is the cause of this exception.

属性

Data Data Data Data

获取提供有关异常的其他用户定义信息的键/值对集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

获取描述当前异常的消息。Gets a message that describes the current exception.

(Inherited from Exception)
Source Source Source Source

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

获取引发当前异常的方法。Gets the method that throws the current exception.

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

当在派生类中重写时,用关于异常的信息设置 SerializationInfoWhen overridden in a derived class, sets the SerializationInfo with information about the exception.

(Inherited from Exception)
GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

创建并返回当前异常的字符串表示形式。Creates and returns a string representation of the current exception.

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

适用于

另请参阅