From 9e02a0573324a0a7455a4d16d36e4c2fe46b8fba Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 28 Aug 2014 19:35:23 +0200 Subject: [PATCH] New: Added automatic detection of a critical bug in mono 3.4.0 to the mono version check. (see mono bug #18599) --- .../HealthCheck/Checks/MonoVersionCheck.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs index 048c90e1c..108af5102 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.EnvironmentInfo; @@ -31,6 +33,12 @@ public override HealthCheck Check() { var version = new Version(versionMatch.Groups["version"].Value); + if (version == new Version(3, 4, 0) && HasMonoBug18599()) + { + _logger.Debug("mono version 3.4.0, checking for mono bug #18599 returned positive."); + return new HealthCheck(GetType(), HealthCheckResult.Error, "your mono version 3.4.0 has a critical bug, you should upgrade to a higher version"); + } + if (version >= new Version(3, 2)) { _logger.Debug("mono version is 3.2 or better: {0}", version.ToString()); @@ -56,5 +64,33 @@ public override bool CheckOnSchedule return false; } } + + private bool HasMonoBug18599() + { + _logger.Debug("mono version 3.4.0, checking for mono bug #18599."); + var numberFormatterType = Type.GetType("System.NumberFormatter"); + + if (numberFormatterType == null) + { + _logger.Debug("Couldn't find System.NumberFormatter. Aborting test."); + return false; + } + + var fieldInfo = numberFormatterType.GetField("userFormatProvider", BindingFlags.Static | BindingFlags.NonPublic); + + if (fieldInfo == null) + { + _logger.Debug("userFormatProvider field not found, version likely preceeds the official v3.4.0."); + return false; + } + + if (fieldInfo.GetCustomAttributes(false).Any(v => v is ThreadStaticAttribute)) + { + _logger.Debug("userFormatProvider field doesn't contain the ThreadStatic Attribute, version is affected by the critical bug #18599."); + return true; + } + + return false; + } } }