diff --git a/Program.cs b/Program.cs index a533aec..99f81e7 100644 --- a/Program.cs +++ b/Program.cs @@ -4,12 +4,14 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2013 Michael Möller + Copyright (C) 2009-2020 Michael Möller */ using System; using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; using OpenHardwareMonitor.GUI; @@ -29,7 +31,7 @@ namespace OpenHardwareMonitor { new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); #endif - if (!AllRequiredFilesAvailable()) + if (!AllRequiredFilesAvailable() || !IsNetFramework45Installed()) Environment.Exit(0); Application.EnableVisualStyles(); @@ -68,6 +70,26 @@ namespace OpenHardwareMonitor { return true; } + private static bool IsNetFramework45Installed() { + Type type; + try { + type = TryGetDefaultDllImportSearchPathsAttributeType(); + } catch (TypeLoadException) { + MessageBox.Show( + "This application requires the .NET Framework 4.5 or a later version.\n" + + "Please install the latest .NET Framework. For more information, see\n\n" + + "https://dotnet.microsoft.com/download/dotnet-framework", + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + return type != null; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Type TryGetDefaultDllImportSearchPathsAttributeType() { + return typeof(DefaultDllImportSearchPathsAttribute); + } + private static void ReportException(Exception e) { CrashForm form = new CrashForm(); form.Exception = e;