How to check if the executable is compatible with the installed version of .NET

I am a software tester. I was given an executable file for testing on this machine. In the test, the executable behaved strangely that no one could explain.

After much research and debugging, I found the reason: an executable file that was created for the .NET target Framework 4.6, but the machine was equipped with .NET 4.5. This caused some "MissingMethodExeception" for even trivial methods such as "string.Format ()". Some attempts to catch these exceptions, but did not treat them correctly, because no one expected them to appear.

Similarly, the problem was described here:

Method not found: 'System.String System.String.Format (System.IFormatProvider, System.String, System.Object)

My questions:

  • Doesn't Windows warn me when I try to run an executable file that cannot be started properly, since the required version of .NET is not available?
  • What is the best practice to solve this problem in general?

(I would expect something like the “Dont execute if target network is unavailable” checkbox in VisualStudio ?!)

+6
source share
2 answers

Doesn't Windows warn me ...

You should definitely get a warning, but not from Windows, but from the CLR. The dialog is as follows , by clicking “Yes”, it automatically receives the required version of the framework, deployed and installed on the computer. The CLR performs this check by looking for the [TargetFramework] attribute embedded in the assembly. As noted, run the ildasm.exe file to verify this attribute. With the expectation that it is either absent or has a fairly low value, so the dialog does not start.

What is the best practice to solve this problem in general?

This is a procedural error; the assembly was not built correctly. You know with great certainty that the compiler used reference assemblies that are suitable only for version .NET 4.6. This needs to be tracked on the machine that built it, most likely it will be a build server. It wasn’t set up correctly, something like the setback that is so common when a civil engineer cuts corners by avoiding using a licensed copy of Visual Studio. Or, using free tools, Jenkins is a common disaster.

Besides the [TargetFramework] attribute being erroneous or missing, this particular loser is especially easy to call. All that is required is to use the assemblies in the c: \ windows \ microsoft.net \ directory as reference assemblies instead of the correct ones that require the targeting package and are installed in the c: \ program files (x86) \ reference assemblysies directory. This Q + A has more potential customers.

Fixing a build server tends to have many resistance points, best done as a tester to report an error. You also want to write one for broken catch-em-all exception handling, which makes it difficult to diagnose the problem.

+1
source

To answer the questions:

  • Windows is not intended to warn you that the .Net Framework is not required to run this executable file. However, Windows logs error or application failure information in the Windows event logs.

Repeat the second question ...

  1. In general, executable files are delivered, deployed, or published using installers. The installer can be configured / written in such a way that they will warn the user if the .Net infrastructure (exe / dll is required) is not installed.
-one
source

Source: https://habr.com/ru/post/1014178/


All Articles