Jump to content

Force .net 4.6 programs to run using 4.0 .net framework


Recommended Posts

Posted (edited)

Hi,

first of all, I made this because I was wondering what changed between .net 4.0 and .net 4.6.1, but this is for a test purpose only.

Let's start!

So... let's just say that technically (but not pratically) it's possible to force 4.6.1 programs to run in Windows XP via 4.0 .net framework, but I'm here to explain why it's a bad idea and what could crash. First of all, the core framework assemblies didn't change in .net 4.6.1 and it still targets v4.0.30319, but, in a program created with the 4.6.1 version, there is a [Target Framework] attribute that says that version 4.6.1 is required (which is not a big deal to "fool"). After that, there is another thing that has been changed by Microsoft and it's about the excutable header of the assemblies, which specifies which version of Windows the exe is compatible with. As we all know, XP belongs to the previous Windows generation and its number is 5 (which changed with Vista, that has number 6). .Net compilers have always specified the minimum version number to be 4.00 (the one that belongs to Windows 9x and NT), but now they specify the subsystem number to 6, but, again, it's possible to manually set it back to 4.00. It is now possible to run programs designed to run using version 4.6.1 BUT they could (probably will) fail if they have to run/load certain things. For instance, classes have been moved from one assembly to another for the [Extention] attribute, which is in System.Core.dll in .net 4.0 (Windows XP) and has been moved to Mscorelib.dll in .net 4.6.1 (well, it has been moved in .net 4.5, if I recall correctly). Let's now suppose that I'm a programmer and that I declare my own extention method. When a user tries to force to run my program in Win XP using .net 4.0, it will try to look to Mscorelib for the attribute (Enabled by a [TypeForwardedTo] attribute in .net 4.6.1 version of System.Core reference assembly), but, of course, isn't there and the program will fail. As to the classes and methods introduced in the newer version of .net 'till 4.6.1, if used, the program will result in a "TypeLoadException" or "MissingMethodException" error if forced to run using .net 4.0.


So... that's about it. This is why it's not a good idea to force programs to load using .net 4.0. How about backporting newer .net to Windows XP? Forget about it: with a few workarounds .net 4.6.1 will install, but it won't run:

Spoiler

 

BRU7hPY.jpg

9CXv83i.jpg

In a nutshell, programmers will have to target .net 4.0, otherwise, I suggest you all to try running programs via mono, which, indeed, has some new features introduced by .Net 4.6.1, but lacks several other features that are available in .net 4.0 as well. So... just... try.

Hope it can be useful to understand a bit what's going on nowadays.

Bye!

Edited by FranceBB

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...