Skip to content

FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the file #136989

Description

@RikkiGibson

Description

See title and file-based app repro below.

Reproduction Steps

#:package Microsoft.Extensions.FileSystemGlobbing@11.0.0-rc.3.26522.148

using Microsoft.Extensions.FileSystemGlobbing;

var root = Path.GetPathRoot(Environment.CurrentDirectory)!;
var matcher = new Matcher();
matcher.AddInclude("MyFile.txt");

Console.WriteLine($"Match(rootDir: \"{root}\", file: \"{root}\")");
Console.WriteLine(matcher.Match(root, root).HasMatches);

Expected behavior

Match() returns a result with HasMatches == false and doesn't throw an exception.

I'm unsure whether it would/should be possible to setup a matcher which would match the path root.

Actual behavior

Match throws an exception:

Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'startIndex')
   at System.String.IndexOfAny(Char[] anyOf, Int32 startIndex, Int32 count)
   at Microsoft.Extensions.FileSystemGlobbing.InMemoryDirectoryInfo.EnumerateFileSystemInfos()+MoveNext()
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at Microsoft.Extensions.FileSystemGlobbing.Internal.MatcherContext.Match(DirectoryInfoBase directory, String parentRelativePath)
   at Microsoft.Extensions.FileSystemGlobbing.Internal.MatcherContext.Execute()
   at Microsoft.Extensions.FileSystemGlobbing.Matcher.Execute(DirectoryInfoBase directoryInfo)
   at Microsoft.Extensions.FileSystemGlobbing.MatcherExtensions.Match(Matcher matcher, String rootDir, IEnumerable`1 files)
   at Microsoft.Extensions.FileSystemGlobbing.MatcherExtensions.Match(Matcher matcher, String rootDir, String file)
   at Program.<Main>$(String[] args)

Regression?

No

Known Workarounds

Check that rootDir != file before calling Match().

Configuration

Using 11.0.100-rc.3.26522.148 SDK to build. Unsure which runtime that means I am running.
Library version given in the sample.
Running on Ubuntu 24.04, x64.
I doubt the problem is configuration-specific, I believe it also repros on Windows.

Other information

Probably here:

int endSegment = file.IndexOfAny(DirectorySeparators, beginSegment, endPath - beginSegment);

Activity

  1. added
    untriaged
    on Nov 4, 2026
  2. dotnet-policy-service commented on Nov 4, 2026

    @dotnet-policy-service
    Contributor

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

  3. removed
    untriaged
    on Nov 5, 2026
  4. added this to the Future milestone on Nov 5, 2026
  5. added a commit that references this issue on Nov 24, 2026
    2eb3bed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions