@@ -4,12 +4,14 @@ This Source Code Form is subject to the terms of the Mozilla Public
44 License, v. 2.0. If a copy of the MPL was not distributed with this
55 file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
7- Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
7+ Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
88
99*/
1010
1111using System ;
1212using System . IO ;
13+ using System . Runtime . CompilerServices ;
14+ using System . Runtime . InteropServices ;
1315using System . Threading ;
1416using System . Windows . Forms ;
1517using OpenHardwareMonitor . GUI ;
@@ -29,7 +31,7 @@ public static void Main() {
2931 new UnhandledExceptionEventHandler ( CurrentDomain_UnhandledException ) ;
3032 #endif
3133
32- if ( ! AllRequiredFilesAvailable ( ) )
34+ if ( ! AllRequiredFilesAvailable ( ) || ! IsNetFramework45Installed ( ) )
3335 Environment . Exit ( 0 ) ;
3436
3537 Application . EnableVisualStyles ( ) ;
@@ -68,6 +70,26 @@ private static bool AllRequiredFilesAvailable() {
6870 return true ;
6971 }
7072
73+ private static bool IsNetFramework45Installed ( ) {
74+ Type type ;
75+ try {
76+ type = TryGetDefaultDllImportSearchPathsAttributeType ( ) ;
77+ } catch ( TypeLoadException ) {
78+ MessageBox . Show (
79+ "This application requires the .NET Framework 4.5 or a later version.\n " +
80+ "Please install the latest .NET Framework. For more information, see\n \n " +
81+ "https://dotnet.microsoft.com/download/dotnet-framework" ,
82+ "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
83+ return false ;
84+ }
85+ return type != null ;
86+ }
87+
88+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
89+ private static Type TryGetDefaultDllImportSearchPathsAttributeType ( ) {
90+ return typeof ( DefaultDllImportSearchPathsAttribute ) ;
91+ }
92+
7193 private static void ReportException ( Exception e ) {
7294 CrashForm form = new CrashForm ( ) ;
7395 form . Exception = e ;
0 commit comments