Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dced143

Browse files
committed
Handle TryGetVersion for single-file exe in netcoreapp3.x.
1 parent 38f6dcb commit dced143

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,16 @@ internal static bool TryGetVersion(out Version? version)
9999
return true;
100100
}
101101

102-
var systemPrivateCoreLib = FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location);
103-
// systemPrivateCoreLib.Product*Part properties return 0 so we have to implement some ugly parsing...
104-
if (TryGetVersionFromProductInfo(systemPrivateCoreLib.ProductVersion, systemPrivateCoreLib.ProductName, out version))
102+
string coreclrLocation = typeof(object).GetTypeInfo().Assembly.Location;
103+
// Single-file publish has empty assembly location.
104+
if (!string.IsNullOrEmpty(coreclrLocation))
105105
{
106-
return true;
106+
var systemPrivateCoreLib = FileVersionInfo.GetVersionInfo(coreclrLocation);
107+
// systemPrivateCoreLib.Product*Part properties return 0 so we have to implement some ugly parsing...
108+
if (TryGetVersionFromProductInfo(systemPrivateCoreLib.ProductVersion, systemPrivateCoreLib.ProductName, out version))
109+
{
110+
return true;
111+
}
107112
}
108113

109114
// it's OK to use this method only after checking the previous ones

0 commit comments

Comments
 (0)