Added a check to verify that at least .NET Framework 4.5 is installed.

This commit is contained in:
Michael Möller 2020-05-25 22:35:46 +02:00
parent 2b9ec17583
commit 566ab46c0a

View File

@ -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 <mmoeller@openhardwaremonitor.org>
Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
*/
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;