Skip to content

Commit 668bba2

Browse files
authored
Catch exceptions when detecting runtime version (#5582)
1 parent 633a5f0 commit 668bba2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Elasticsearch.Net/Connection/MetaData/RuntimeVersionInfo.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,24 @@ internal sealed class RuntimeVersionInfo : VersionInfo
4545

4646
public RuntimeVersionInfo() => StoreVersion(GetRuntimeVersion());
4747

48-
private static string GetRuntimeVersion() =>
48+
private static string GetRuntimeVersion()
49+
{
50+
try
51+
{
4952
#if !DOTNETCORE
50-
GetFullFrameworkRuntime();
53+
return GetFullFrameworkRuntime();
5154
#else
52-
GetNetCoreVersion();
55+
return GetNetCoreVersion();
5356
#endif
57+
}
58+
catch
59+
{
60+
// Swallow these to avoid crashing, just because we fail to detect the framework.
61+
// Mostly affects Xamarin Forms.
62+
}
63+
64+
return null;
65+
}
5466

5567
#if DOTNETCORE
5668
private static string GetNetCoreVersion()
@@ -65,7 +77,7 @@ private static string GetNetCoreVersion()
6577
return RuntimeInformation.FrameworkDescription.Substring(dotNet.Length);
6678
}
6779
}
68-
80+
6981
// next, try using file version info
7082
var systemPrivateCoreLib = FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location);
7183
if (TryGetVersionFromProductInfo(systemPrivateCoreLib.ProductVersion, systemPrivateCoreLib.ProductName, out var runtimeVersion))

0 commit comments

Comments
 (0)