Skip to content

Commit f63e50c

Browse files
committed
Get highest AssemblyFileVersionAttribute version (#4270)
This commit updates the FrameworkDescription logic used to determine the .NET framework version from the AssemblyFileVersionAttribute on the assembly containing the base object type to 1. Get all AssemblyFileVersionAttribute attributes 2. order by versioning descending 3. get the first version This is to workaround an edge case in using this technique to get the .NET Framework version that appears to affect running an application under full framework in IIS. Fixes #4189. (cherry picked from commit 9cf9ce4)
1 parent 334dd4e commit f63e50c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Elasticsearch.Net/Api/RuntimeInformation.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
#if NET461
34
using System.Reflection;
45

@@ -16,7 +17,11 @@ public static string FrameworkDescription
1617
if (_frameworkDescription == null)
1718
{
1819
var assemblyFileVersionAttribute =
19-
(AssemblyFileVersionAttribute)typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute));
20+
((AssemblyFileVersionAttribute[])Attribute.GetCustomAttributes(
21+
typeof(object).GetTypeInfo().Assembly,
22+
typeof(AssemblyFileVersionAttribute)))
23+
.OrderByDescending(a => a.Version)
24+
.First();
2025
_frameworkDescription = $".NET Framework {assemblyFileVersionAttribute.Version}";
2126
}
2227
return _frameworkDescription;

src/Nest/CrossPlatform/RuntimeInformation.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
#if NET461
34
using System.Reflection;
45

@@ -16,7 +17,11 @@ public static string FrameworkDescription
1617
if (_frameworkDescription == null)
1718
{
1819
var assemblyFileVersionAttribute =
19-
(AssemblyFileVersionAttribute)typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute));
20+
((AssemblyFileVersionAttribute[])Attribute.GetCustomAttributes(
21+
typeof(object).GetTypeInfo().Assembly,
22+
typeof(AssemblyFileVersionAttribute)))
23+
.OrderByDescending(a => a.Version)
24+
.First();
2025
_frameworkDescription = $".NET Framework {assemblyFileVersionAttribute.Version}";
2126
}
2227
return _frameworkDescription;

0 commit comments

Comments
 (0)