Bug Report: Path.GetDirectoryName incorrectly removes "//" from the start of paths.

Hi,

While integrating the new version of FMOD (1.07 Unity Integration 2), I found that FMOD settings would not detect the builds folder over the network (separate hostname), yet would detect the actual project file no problem.

After investigation, we have found that mono’s implementation of the Path.GetDirectoryName function does not preserve ‘//’ on the start of paths. Therefore losing the hostname from the path and failing detection of the builds folder.

i.e. (the following is inclusive of escape characters): ‘//’ becomes ‘\\’ when it should become ‘\\\\’. The reason ‘//’ becomes ‘\\’ is because mono tries to remove duplicate delimiters.

I have temporarily fixed this in the two relevant places with the code:

	if (projectPath.StartsWith("//"))
	{
		projectFolder = "\\" + projectFolder;
	}

For reference, the places affected by this issue are both in EditorUtils.cs. Lines 30 and 61.

Kind Regards,
Steve

Thanks Steve we’ll look into this for the next release.

1 Like

Can I clarify what platform this is on? Windows UNC paths must start with ‘\\’. Other separators can be forward of back slashes.

Sorry, this occurred on Windows.

Kind Regards,
Steve

I think the solution is to use the correct UNC path starting with ‘\\’ rather than changing the code to silently fix incorrect input.

This makes the assumption that you’re not working with cross platform paths. The fact is that Mono’s implementation of the Path.GetDirectoryName is incorrect. A bit of googling shows that the source actually is incorrect, and the .NET framework’s implementation of this function has a specific line of code (which is even commented) which works around this issue.

Path.GetDirectoryName should return you the correct path regardless of the delimiter used in the input path, therefore using “//” as opposed to “\” is not incorrect input.

Kind Regards,
Steve

Furthermore, it is not the user’s code that sets the path and delimiter. The event paths generated by FMOD use forward slash in their paths regardless of the platform.

Kind Regards,
Steve

If I use the directory selector on Windows it give me the correct UNC paths.