none
clr loads a different assembly version 4.7.2 not 4.6.2 that is targeted when building RRS feed

  • Question

  • I use visual studio to create a project which targets .net framework 4.6.2,when running my app I have found clr loaded mscorlib.dll assembly version 4.7.2 ,obviously 4.7.2 is the newest version of assembly . But why and how can I force clr to load 4.6.2 assebmly?
    Thursday, January 18, 2018 2:24 PM

All replies

  • That isn't how the CLR works. There is only 1 CLR v4 on a machine and it is whatever version was installed. 4.6.2 is older than 4.7.2 so if a user installs 4.7.2 then it overwrites the 4.6.2 runtime.

    It is important to note that the .NET framework and the CLR are technically different. Your app will target a framework version but it runs against the runtime version. There has been only 3 versions of the CLR (v1, v2 and v4). There have been many versions of the framework. The framework version is used for tooling support and to identify what version of the CLR you run against. .NET 1.x runs against CLR v1, .NET 2.x and 3.x run against v2 and .NET 4.x runs against v4. 

    Technically any .NET 4.x app runs against 4.7.2. But newer framework versions generally introduce new config settings to adjust the behavior of the CLR in some cases. So there are a couple of cases where the CLR will behave differently when running an app that doesn't specify it supports 4.7 (or 4.6 or whatever) but this isn't common. In general apps run against 4.7 version of the runtime the same as they would the 4.6.

    https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies

    https://blogs.msdn.microsoft.com/karinm/2008/11/10/whats-the-difference-between-clr-and-net-framework/

    https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/application-compatibility

    So, in summary, nothing you can do. Whatever version of the CLR v4 is installed on the machine is the version that the app will run against.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, January 18, 2018 3:05 PM
    Moderator
  • now i have built an app target 4.5 and 4.6.2 has been installed in my windows. When i begin to debug the app , I find mscorlib.dll loaded , to my surprise that mscorlib.dll file version is 4.6.2 .

    What happened ? I have expected the version of mscorlib.dll is 4.5 . but the clr like loading the newest version of assembly file and gac is the first choice for clr.

    Friday, January 19, 2018 1:56 AM
  • Again, it doesn't matter what version you're compiling against of the .NET 4.x framework. There is only 1 CLR v4 installed on a machine. Your app will always use whatever that version is. If .NET 4.6.2 is installed on the machine then you'll be using 4.6.2. If the user installed 4.7 then you'll be using it. CLRs are not installed side by side unless they are different major versions (v1, v2, v4).

    Your selection of target framework mostly just drives the target CLR version (v4 in this case) and the options given to you in the IDE. Only minor changes (generally backed by config entries) are generally impacted by the different minor versions of the CLR. There are a few exceptions.

    The documentation I linked to along with other information posted in MSDN covers this in detail.


    Michael Taylor http://www.michaeltaylorp3.net

    Friday, January 19, 2018 2:21 AM
    Moderator
  • THank you so much.I still have no idea to uninstall 4.7.2 . When debugging in VS , in the module view , The file version of mscorlib.dll is 4.7.2 ,below is the picture:

    but it targets 4.6.1 when building .

    How can i achieve it ?

    Thans again.


    Saturday, January 20, 2018 12:13 AM
  • "How can i achieve it ?"

    You cannot. You will always, always run against the version of the CLR v4 installed on the target machine. Without exception. .NET does not support running against a specific version of the (v4) runtime based upon whatever you selected as the target framework. The target framework simply identifies the base CLR version you're targeting. The app will always run against the (only) version installed on the target machine. There is no workaround for this as it is by design.

    The only way to run against a very specific version of the CLR is to uninstall the .NET framework from the target machine and then install the runtime for a specific version that you want. However since .NET 4 has been out for years you most likely won't be able to uninstall it without rendering the target machine broken.  Also note that you cannot do this on a machine with VS 2017 (or even earlier) installed as this will break VS completely.

    Once the target machine is updated to the newer framework version (which often happens when installing applications or even Windows updates) then you'll be back to the version of the framework currently installed on the target machine.

    In test environments, where you need to control the exact version of the framework installed, the approach is to install the base OS (ensuring that it doesn't have a newer version of the framework installed - for example Windows 10). Then applying the .NET framework update that you want. But at that point the machine cannot be upgraded anymore otherwise it will overwrite the framework version.

    Reminder, there can be only 1 version of the .NET 4 framework installed on a machine. It is basically an upgrade only approach. There is no downgrade options.


    Michael Taylor http://www.michaeltaylorp3.net

    Saturday, January 20, 2018 12:51 AM
    Moderator