Skip to content
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

Avoid Unhandled Exception on .NET 461 if the Registry Access threw an exception. #1101

Merged
merged 32 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f992746
ignore registry errors (would be nice to log it)
lucas-zimerman Jul 1, 2021
61b623c
remove changes.
lucas-zimerman Jul 1, 2021
ef99719
wip
lucas-zimerman Jul 2, 2021
903f92b
WIP
lucas-zimerman Jul 2, 2021
0b9fb5a
update changelog.
lucas-zimerman Jul 2, 2021
0002382
Merge branch 'main' into feat/opt-out-netfxinstalaltions
lucas-zimerman Jul 5, 2021
5140c39
Moved error handling flow for Registry reading
lucas-zimerman Jul 5, 2021
df81d98
const params
lucas-zimerman Jul 5, 2021
85d84dd
replaced tryopenregistry by Registry.LocalMachine.TryOpenSubKey
lucas-zimerman Jul 5, 2021
0cd35c6
Update src/Sentry/PlatformAbstractions/FrameworkInfo.NetFx.cs
lucas-zimerman Jul 5, 2021
2b46fca
wip
lucas-zimerman Jul 5, 2021
3b93b36
Changed exception flow + fixed changelog.
lucas-zimerman Jul 6, 2021
21590e3
removed unused return
lucas-zimerman Jul 6, 2021
7795ca3
fixed changelog and exception flow.
lucas-zimerman Jul 7, 2021
772063d
Revert manual test
lucas-zimerman Jul 7, 2021
a4efea1
Merge branch 'main' into feat/opt-out-netfxinstalaltions
lucas-zimerman Jul 7, 2021
bd31d7d
removed spaces.
lucas-zimerman Jul 7, 2021
4d345b4
Apply suggestions from code review
lucas-zimerman Jul 7, 2021
1590d4e
Merge branch 'feat/opt-out-netfxinstalaltions' of https://github.com/…
lucas-zimerman Jul 8, 2021
7eeed1b
Update src/Sentry/SentryOptions.cs
lucas-zimerman Jul 8, 2021
ae3d816
remove white line
lucas-zimerman Jul 8, 2021
04659b2
Merge branch 'feat/opt-out-netfxinstalaltions' of https://github.com/…
lucas-zimerman Jul 8, 2021
c1337a7
rollback hub try/catch on Register
lucas-zimerman Jul 8, 2021
3f9e65a
Merge branch 'main' into feat/opt-out-netfxinstalaltions
lucas-zimerman Jul 8, 2021
8930405
exception log on NetFxInstallationIntegration.
lucas-zimerman Jul 8, 2021
0f32c44
Merge branch 'feat/opt-out-netfxinstalaltions' of https://github.com/…
lucas-zimerman Jul 8, 2021
b07e2d0
remove unused using.
lucas-zimerman Jul 8, 2021
03c4929
removed PR from changelog.
lucas-zimerman Jul 8, 2021
8928c6e
Apply suggestions from code review
lucas-zimerman Jul 10, 2021
1e6cce5
Merge branch 'main' into feat/opt-out-netfxinstalaltions
bruno-garcia Jul 10, 2021
a15349b
fix StackTrageMode return
lucas-zimerman Jul 10, 2021
58a0cd7
Merge branch 'main' into feat/opt-out-netfxinstalaltions
bruno-garcia Jul 10, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Avoid Unhandled Exception on .NET 461 if the Registry Access threw an exception([#1101](https://github.com/getsentry/sentry-dotnet/pull/1101))
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
- `IHub.ResumeSession()`: don't start a new session if pause wasn't called or if there is no active session ([#1089](https://github.com/getsentry/sentry-dotnet/pull/1089))
- Fixed incorrect order when getting the last active span ([#1094](https://github.com/getsentry/sentry-dotnet/pull/1094))
- Fix logger call in BackgroundWorker that caused a formatting exception in runtime ([#1092](https://github.com/getsentry/sentry-dotnet/pull/1092))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<OutputType>Exe</OutputType>
<!--Version is detected by default as the application release and sent to sentry-->
<Version>9.8.7</Version>
<TargetFramework>net5.0</TargetFramework>
<TargetFrameworks>net5.0;netcoreapp2.1;net461</TargetFrameworks>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../src/Sentry/Sentry.csproj" />
</ItemGroup>

</Project>
36 changes: 29 additions & 7 deletions src/Sentry/PlatformAbstractions/FrameworkInfo.NetFx.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if NET461
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Win32;

namespace Sentry.PlatformAbstractions
Expand All @@ -10,6 +11,8 @@ namespace Sentry.PlatformAbstractions
/// </summary>
public static partial class FrameworkInfo
{
internal const string NetFxNdpRegistryKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\";
internal const string NetFxNdpFullRegistryKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
/// <summary>
/// Get the latest Framework installation for the specified CLR
/// </summary>
Expand All @@ -20,7 +23,7 @@ public static partial class FrameworkInfo
/// CLR 4 => .NET 4.0, 4.5.x, 4.6.x, 4.7.x
/// </remarks>
/// <param name="clrVersion">The CLR version: 1, 2 or 4</param>
/// <returns>The framework installation or null if none is found.</returns>
/// <returns>The framework installation or null if none is found, used for fine-tuning the Latest info.</returns>
public static FrameworkInstallation? GetLatest(int clrVersion)
{
// CLR versions
Expand Down Expand Up @@ -85,8 +88,19 @@ public static partial class FrameworkInfo
/// <returns>Enumeration of installations</returns>
public static IEnumerable<FrameworkInstallation> GetInstallations()
{
using var ndpKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, string.Empty)
.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\");
try
{
using var ndpKey = Registry.LocalMachine.OpenSubKey(NetFxNdpRegistryKey, false);
return GetInstallationsFromRegistryKey(ndpKey).ToArray();
}
catch
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
{
return null;
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved
}
}

internal static IEnumerable<FrameworkInstallation> GetInstallationsFromRegistryKey(RegistryKey? ndpKey)
{
if (ndpKey == null)
{
yield break;
Expand Down Expand Up @@ -160,16 +174,24 @@ private static FrameworkInstallation GetFromV4(RegistryKey subKey, string subKey
},
Version = version,
ServicePack = subKey.GetInt("SP"),
Release = hasRelease ? release : null as int?
Release = hasRelease ? release : null
};
}

// https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#to-find-net-framework-versions-by-querying-the-registry-in-code-net-framework-45-and-later
internal static int? Get45PlusLatestInstallationFromRegistry()
{
using var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\");
return ndpKey?.GetInt("Release");
{
try
{
using var ndpKey = Registry.LocalMachine.OpenSubKey(NetFxNdpFullRegistryKey, false);
return ndpKey?.GetInt("Release");
}
catch
{
return null;
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

internal static Version GetNetFxVersionFromRelease(int release)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.Win32;
using Sentry.Extensibility;

namespace Sentry.PlatformAbstractions
Expand All @@ -23,7 +24,8 @@ internal class NetFxInstallationsEventProcessor : ISentryEventProcessor
internal static Dictionary<string, string> GetInstallationsDictionary()
{
var versionsDictionary = new Dictionary<string, string>();
var installations = FrameworkInfo.GetInstallations().ToArray();
using var registryKey = Registry.LocalMachine.OpenSubKey(FrameworkInfo.NetFxNdpRegistryKey, false);
var installations = FrameworkInfo.GetInstallationsFromRegistryKey(registryKey).ToArray();
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
foreach (var profile in installations.Select(p => p.Profile).Distinct())
{
versionsDictionary.Add($"{NetFxInstallationsKey} {profile}",
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/PlatformAbstractions/RuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ internal static void SetNetFxReleaseAndVersion(Runtime runtime)
var latest = FrameworkInfo.GetLatest(Environment.Version.Major);

runtime.FrameworkInstallation = latest;
if (latest.Version?.Major < 4)
if (latest?.Version?.Major < 4)
{
// prior to 4, user-friendly versions are always 2 digit: 1.0, 1.1, 2.0, 3.0, 3.5
runtime.Version = latest.ServicePack == null
? $"{latest.Version.Major}.{latest.Version.Minor}"
: $"{latest.Version.Major}.{latest.Version.Minor} SP {latest.ServicePack}";
}
else
else if (latest != null)
{
runtime.Version = latest.Version?.ToString();
}
Expand Down