Add DirectoryPath property to DirectoryNotFoundException#126428
Add DirectoryPath property to DirectoryNotFoundException#126428ViveliDuCh merged 7 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-io |
There was a problem hiding this comment.
Pull request overview
Adds a DirectoryPath property and related API surface to System.IO.DirectoryNotFoundException to enable machine-readable access to the missing directory path (similar to FileNotFoundException.FileName).
Changes:
- Added
DirectoryPathproperty and new constructor overloads acceptingdirectoryPath. - Implemented
MessageandToString()overrides to incorporateDirectoryPath(including auto-message whenmessageis null). - Added serialization support and updated reference assembly and tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs | Implements DirectoryPath property, new constructors, Message/ToString() overrides, and serialization plumbing. |
| src/libraries/System.Private.CoreLib/src/Resources/Strings.resx | Adds new localized strings used for message/to-string formatting. |
| src/libraries/System.Runtime/ref/System.Runtime.cs | Updates ref assembly to include the new constructors, property, and overrides. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/IO/DirectoryNotFoundExceptionTests.cs | Adds unit tests covering the new API surface and formatting behaviors. |
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
…n. Update tests and SR strings.
cc6f9cb to
c4ad204
Compare
When we introduce new APIs that can be used within the BCL, we typically add their use within the BCL as part of same PR to validate that the API actually works well in practice. |
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Outdated
Show resolved
Hide resolved
...ries/System.Security.AccessControl/src/System/Security/AccessControl/NativeObjectSecurity.cs
Show resolved
Hide resolved
...s/System.IO.FileSystem.AccessControl/src/System/Security/AccessControl/FileSystemSecurity.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Show resolved
Hide resolved
…alization and null-coalesce message in ctors/drop Message override.
41b077d to
b412c84
Compare
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs
Show resolved
Hide resolved
...aries/System.Runtime/tests/System.Runtime.Tests/System/IO/DirectoryNotFoundExceptionTests.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Show resolved
Hide resolved
0241794 to
3974814
Compare
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/DirectoryNotFoundException.cs
Outdated
Show resolved
Hide resolved
3974814 to
a27f22c
Compare
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
|
/ba-g Build Analysis stuck idle (2+ days, no re-run option). Failure is MacCatalyst infra issue: XHarness exit 82 (RETURN_CODE_NOT_SET), test runner couldn't read app exit code (empty log). Previous run passed. |
Closes #103468
Adds a
DirectoryPathproperty toDirectoryNotFoundExceptionas approved in API review.What's included
DirectoryPathnullable property onDirectoryNotFoundException, matching the pattern ofFileNotFoundException.FileNamedirectoryPath(message + directoryPath,message + directoryPath + innerException)messageis null butdirectoryPathis provided, via null-coalescing in the constructorsToString()override that includesDirectoryPathon a separate lineGetObjectData/ version-tolerant deserialization constructorSystem.RuntimeArg_DirectoryNotFoundExceptiondefault message from"Attempted to access a path that is not on the disk."to"Unable to find the specified directory."to matchFileNotFoundException's"Unable to find the specified file."pattern and align better with the newIO_DirectoryNotFound_Pathstring.ToString()output, null edge cases, and serialization round-tripImplementation notes
FileNotFoundExceptionimplementation pattern:string?(nullable) because not all throw sites have a path availablemessage(consistent with existing DNFE constructors), auto-constructing a descriptive message fromdirectoryPathwhenmessageis nullSR.Format(...)for message construction rather than native interop, as recommended during API reviewSerializationInfoentries to handle old payloads that lack theDirectoryPathfield#if NET11_0_OR_GREATERguards on throw sites in multi-TFM files (Win32Marshal.cs,Interop.IOErrors.cs,PhysicalFileProvider.cs,LdapSessionOptions.Linux.cs) since the new constructor isn't available on older TFM targetsInternal throw-site updates
Updated 18 internal throw sites across 12 files to pass directory paths to the new constructors, so that
DirectoryPathis populated for runtime-generated exceptions:Win32Marshal.cspathInterop.IOErrors.cs(Unix ENOTDIR)pathFileInfo.cs(MoveTo)FullNameFileSystem.Unix.cs(×2, directory rename)sourceFullPathTarFile.cs(×8)sourceDirectoryName/destinationDirectoryNameIsolatedStorageFile.cssourceDirectoryNameFileSystemSecurity.csnameSocketAsyncEventArgs.Unix.csdirnameNativeObjectSecurity.csnameLdapSessionOptions.Linux.csvaluePhysicalFileProvider.csRootNot updated (by design):
SharedMemoryManager.Unix.csdefault ctor,Interop.IOErrors.csempty-path branch,FileSystemSecurity.csnull-name branch)EventWaitHandle,Mutex,EventWaitHandleAcl,MutexAcl) where thenameis a named sync object, not a filesystem directory