Skip to content

Catch exceptions when detecting runtime version #5582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Elasticsearch.Net/Connection/MetaData/RuntimeVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,24 @@ internal sealed class RuntimeVersionInfo : VersionInfo

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

private static string GetRuntimeVersion() =>
private static string GetRuntimeVersion()
{
try
{
#if !DOTNETCORE
GetFullFrameworkRuntime();
return GetFullFrameworkRuntime();
#else
GetNetCoreVersion();
return GetNetCoreVersion();
#endif
}
catch
{
// Swallow these to avoid crashing, just because we fail to detect the framework.
// Mostly affects Xamarin Forms.
}

return null;
}

#if DOTNETCORE
private static string GetNetCoreVersion()
Expand All @@ -65,7 +77,7 @@ private static string GetNetCoreVersion()
return RuntimeInformation.FrameworkDescription.Substring(dotNet.Length);
}
}

// next, try using file version info
var systemPrivateCoreLib = FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location);
if (TryGetVersionFromProductInfo(systemPrivateCoreLib.ProductVersion, systemPrivateCoreLib.ProductName, out var runtimeVersion))
Expand Down