diff --git a/src/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj b/src/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj index 2a78ce99e3..b2507fe438 100644 --- a/src/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj +++ b/src/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj @@ -13,6 +13,7 @@ + \ No newline at end of file diff --git a/src/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj b/src/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj index 9d407936ba..8d94dbfa19 100644 --- a/src/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj +++ b/src/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj @@ -60,6 +60,7 @@ + diff --git a/src/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs b/src/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs index ed9237c324..3bbf07f612 100644 --- a/src/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs +++ b/src/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs @@ -265,6 +265,12 @@ namespace System.Diagnostics /// public static FileVersionInfo GetVersionInfo(string fileName) { + // Check if fileName is a full path. Relative paths can cause confusion if the local file has the .dll extension, + // as .dll search paths can take over & look for system .dll's in that case. + if (!Path.IsPathFullyQualified(fileName)) + { + fileName = Path.GetFullPath(fileName); + } // Check for the existence of the file. File.Exists returns false if Read permission is denied. if (!File.Exists(fileName)) { diff --git a/src/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/FileVersionInfoTest.cs b/src/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/FileVersionInfoTest.cs index d273df3ad4..bc1f24d941 100644 --- a/src/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/FileVersionInfoTest.cs +++ b/src/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/FileVersionInfoTest.cs @@ -102,6 +102,21 @@ namespace System.Diagnostics.Tests FileVersionInfo.GetVersionInfo(Path.Combine(Directory.GetCurrentDirectory(), TestNotFoundFileName))); } + [Fact] + [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Don't want to create temp file in app container current directory")] + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NetFX throws ArgumentException in this case")] + public void FileVersionInfo_RelativePath_CorrectFilePath() + { + using (new FileStream("kernelbase.dll", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 0x1000, FileOptions.DeleteOnClose)) + { + FileVersionInfo fvi = FileVersionInfo.GetVersionInfo("kernelbase.dll"); + //File name should be the full path to the local kernelbase.dll, not the relative path or the path to the system .dll + Assert.Equal(Path.GetFullPath("kernelbase.dll"), fvi.FileName); + //FileDescription should be null in the local kernelbase.dll + Assert.Equal(null, fvi.FileDescription); + } + } + // Additional Tests Wanted: // [] File exists but we don't have permission to read it // [] DLL has unknown codepage info