From: Mike on
Hi! On some Windows 7 machines I am getting the following error when I
execute this code to enumerate all named pipes on a PC:

string[] pipeNames = null;
try
{
pipeNames = System.IO.Directory.GetFiles(@"\\.\pipe\");
}
catch (Exception ex)
{
}

ERROR:
System.ArgumentException: Second path fragment must not be a drive or UNC
name.

Parameter name: path2

at System.IO.Path.InternalCombine(String path1, String path2)

at System.IO.Directory.InternalGetFileDirectoryNames(String path, String
userPathOriginal, String searchPattern, Boolean includeFiles, Boolean
includeDirs, SearchOption searchOption)

at System.IO.Directory.GetFiles(String path, String searchPattern,
SearchOption searchOption)

at System.IO.Directory.GetFiles(String path)

I can not put my finger on what would cause some Windows 7 PC's crash and
some work perfectly fine. It also works fine on Vista

Any ideas/suggestions/help is greatly appreciated.


From: Peter Duniho on
Mike wrote:
> [...]
> I can not put my finger on what would cause some Windows 7 PC's crash and
> some work perfectly fine. It also works fine on Vista
>
> Any ideas/suggestions/help is greatly appreciated.

Based on the information provided, I would say that the "path2" argument
to the InternalCombine() method is being set to something that looks
like a drive or UNC name.

If you can get Microsoft's source server configuration to work, you can
easily step through the .NET code that's causing the exception. That
said, I think ultimately you will find that the real issue is that
you're trying to do something for which the GetFiles() method wasn't
intended (i.e. enumerate named pipes). Probably it just happens that on
some computers, when the InternalGetFileDirectoryNames() gets tricked
into trying to enumerate the named pipes, some pipe comes along with a
name that looks like a drive or UNC name, hence the exception.

Since that would depend on what named pipes happened to exist at the
time you executed the code, I could easily see the behavior varying from
PC to PC, depending on configuration and the exact state of the machine.

Of course, only by debugging the problem would you be able to know for
sure. But I'm not aware of any promise on .NET's part that you _should_
be able to use GetFiles() to enumerate named pipes, so the real answer
is probably just "don't do that."

Pete