From 1cdde374e6a6477c83b08a219a4724787071f655 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos <6349682+vaind@users.noreply.github.com> Date: Sat, 26 Mar 2022 01:06:38 +0100 Subject: [PATCH] chore: wrap GetFromRuntimeInformation() in try-catch (#1554) --- .../PlatformAbstractions/RuntimeInfo.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Sentry/PlatformAbstractions/RuntimeInfo.cs b/src/Sentry/PlatformAbstractions/RuntimeInfo.cs index d8970de0f6..5ba99091b9 100644 --- a/src/Sentry/PlatformAbstractions/RuntimeInfo.cs +++ b/src/Sentry/PlatformAbstractions/RuntimeInfo.cs @@ -102,11 +102,20 @@ internal static void SetNetCoreVersion(Runtime runtime) internal static Runtime? GetFromRuntimeInformation() { - // Preferred API: netstandard2.0 - // https://github.com/dotnet/corefx/blob/master/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs - // https://github.com/mono/mono/blob/90b49aa3aebb594e0409341f9dca63b74f9df52e/mcs/class/corlib/System.Runtime.InteropServices.RuntimeInformation/RuntimeInformation.cs - // e.g: .NET Framework 4.7.2633.0, .NET Native, WebAssembly - var frameworkDescription = RuntimeInformation.FrameworkDescription; + string frameworkDescription; + try + { + // Preferred API: netstandard2.0 + // https://github.com/dotnet/corefx/blob/master/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs + // https://github.com/mono/mono/blob/90b49aa3aebb594e0409341f9dca63b74f9df52e/mcs/class/corlib/System.Runtime.InteropServices.RuntimeInformation/RuntimeInformation.cs + // e.g: .NET Framework 4.7.2633.0, .NET Native, WebAssembly + // Note: this throws on some Unity IL2CPP versions + frameworkDescription = RuntimeInformation.FrameworkDescription; + } + catch + { + return null; + } return Parse(frameworkDescription); }