Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Path.Combine ever make network calls in .net?

Someone I know is claiming that it does and I am decompiling System.IO and looking in the Path class and I can't see it making networking calls. The only suspect is in NormalizePath, where it calls to PathHelper which has calls into Win32Native.GetFullPathName. I don't know what that does.

They are also claiming that System.Uri makes networking calls when created, which I find very incredible. I just can't believe that it would do that given how unbelievably slow that would be and how intrinsic these methods are.

Can anyone enlighten me?

Edit: It turns out that Path.Combine(p) doesn't ever call the network but Path.GetFullName(p) can. In the scenario where you have a UNC path with a short filename ("\\server\abcdef~1.txt" for example) it will actually call out to the network and try to expand the path, which blows my mind frankly.

like image 874
justin.m.chase Avatar asked Feb 14 '12 22:02

justin.m.chase


1 Answers

No, the Path.Combine method simply performs the required string manipulation to generate a legal path string, given the path separator. It explicitly does not check to see if you've given it a valid path, or a valid file name, or whatever.

The reference source code for .NET 4 is available, if you're curious, and you can see that the work is done entirely in managed code, no native method calls, and is basically:

return path1 + (path1.EndsWidth("\") ? "" : "\") + path2;

(A lot more robust and flexible, of course, but that's the idea.)

Similarly, the constructors for the Uri class do mostly string parsing (though orders of magnitude more complex than the Path stuff) but still, no network calls that I can see.

You could also check this yourself by running a packet capture utility such as Wireshark while executing such commands in a C# app.

like image 146
Michael Edenfield Avatar answered Sep 24 '22 06:09

Michael Edenfield