Skip to content

BCL: Encountering System.NullReferenceException when 'enumerationOptions' parameter of Directory.EnumerateFiles method is null #114623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hrumhurum opened this issue Apr 14, 2025 · 3 comments · May be fixed by #114672
Labels
area-System.IO help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@hrumhurum
Copy link

Description

The following methods throw System.NullReferenceException when their enumerationOptions parameter is null:

  • Directory.EnumerateFiles(String, String, EnumerationOptions)
  • Directory.EnumerateDirectories(String, String, EnumerationOptions)
  • Directory.EnumerateFileSystemEntries(String, String, EnumerationOptions)

Instead, they should throw System.ArgumentNullException when enumerationOptions parameter is null.

Reproduction Steps

Directory.EnumerateFiles(@"C:\", "*", (EnumerationOptions)null);

Expected behavior

  • System.ArgumentNullException: Value cannot be null. (Parameter 'enumerationOptions')

Actual behavior

  • System.NullReferenceException: Object reference not set to an instance of an object.

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK 9.0.203

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 14, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 14, 2025
@filipnavara filipnavara added area-System.IO and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 14, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

@stephentoub
Copy link
Member

Please feel free to submit a PR to fix it. Thanks.

@jozkee jozkee added this to the Future milestone Apr 14, 2025
@jozkee jozkee added help wanted [up-for-grabs] Good issue for external contributors and removed untriaged New issue has not been triaged by the area owner labels Apr 14, 2025
@huoyaoyuan huoyaoyuan linked a pull request Apr 15, 2025 that will close this issue
@hrumhurum
Copy link
Author

@huoyaoyuan, thank you for providing the PR, looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants