Last active
February 17, 2022 07:42
-
-
Save Zalexanninev15/ccaa6277ae09bac92ac561b892bc1772 to your computer and use it in GitHub Desktop.
Is .NET Framework 4.5 or a later version installed? If not, install this...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Although the method works, it would be better to check the installed versions | |
of .NET Framework in this article (there is a code to determine the version in C#): | |
https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed | |
*/ | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment