All file enumerations methods fail with System.IO.IOException: 'An unexpected network error occurred' when enumerating large network foler structures

Open
#108,381 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp

Research direction

Start by reproducing the failure through Directory.GetFiles with the shown EnumerationOptions against the large Synology SMB3 structure, then compare it with the other file-enumeration methods named in the report. Trace the relevant System.IO enumeration entry points and establish why network enumeration fails after about five minutes; done means the same structure enumerates successfully without the reported IOException.

Written by the indexing model from the issue text.

Description

area-System.IO needs-further-triage
Description

Enumeration fails when using any of the file enumeration methods such as File.IO.GetFiles, EnumerateFiles, EnumerateFileSystemEntries or DirectoryInfo.... on large network structures.

x86 and x64 debug in VS, running against a Synology NAS using SMB3 on a local network - folder has about 1.2 million files in 60k folders.

Reproduction Steps

EnumerationOptions enumerationOptions = new() { BufferSize = 65535, IgnoreInaccessible = true, RecurseSubdirectories = true, AttributesToSkip = FileAttributes.Device };
var files = Directory.GetFiles(testPath, "*", enumerationOptions);

Expected behavior

It should be able to enumerate the files - It works fine on the same file structure for SSD and HDD, just not over the network.

Actual behavior

After about 5 minutes, all enumeration methods fail with System.IO.IOException: 'An unexpected network error occurred'

Regression?

Error is on .net 6,7,8,9

Known Workarounds

Enumerate folder by folder via recursion in code

Configuration

.Net 9
Windows 11 23H2 x64
Issue is the same from a Windows 10 test machine

Other information

No response

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.