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

Closed
hrumhurum opened this issue Apr 14, 2025 · 3 comments · 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

@ghost ghost 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
@hrumhurum
Copy link
Author

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

@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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