Из corefx документация для System.IO.Path.GetDirectoryName
метода:
/// <summary>
/// Returns the directory portion of a file path. This method effectively
/// removes the last segment of the given file path, i.e. it returns a
/// string consisting of all characters up to but not including the last
/// backslash ("\") in the file path. The returned value is null if the
/// specified path is null, empty, or a root (such as "\", "C:", or
/// "\\server\share").
/// </summary>
/// <remarks>
/// Directory separators are normalized in the returned string.
/// </remarks>
public static string GetDirectoryName(string path)
{
if (path == null || PathInternal.IsEffectivelyEmpty(path.AsSpan()))
return null;
int end = GetDirectoryNameOffset(path.AsSpan());
return end >= 0 ? PathInternal.NormalizeDirectorySeparators(path.Substring(0, end)) : null;
}
, поэтому она не такая, как в полной версии фреймворка, и возвращает null
, если указанный путь является нулевым, пустой или рут.Ожидаемое поведение