none
Reference a assembly compiled against .NET 4 CLR from a .NET 2 CLR RRS feed

  • Question

  • Hi,

    I just read this aricle http://msdn.microsoft.com/en-us/magazine/ee819091.aspx. In Figure 2 (Will These Runtimes Load in the Same Process?) You can read that it is OK to load an assembly compiled against .NET 4 CLR from an application compiled against .NET 2 CLR. But later in the aricle under "Library Developers and Consumers " you can read that it will not work for libraries.

    I have a web application (ASP.NET) compiled against .NET 2 CLR that needs to reference an assembly compiled against .NET 4 CLR. Will this work or not? I have tried it several times and it works fine. I don't understand the text in the aricle becase Figure 2 says it's OK but the text under "Library Developers" says it will not be OK. But for me it works. Maybe I have just had luck?

    Saturday, September 4, 2010 1:49 PM

Answers

  • Right - CLR version 2 can load libraries/assemblies using .NET 2, 3, and 3.5.

    For an app to load .NET Frameworki version 4 assemblies, the app needs to be running under CLR version 4.

    Note that this can be confusing since the CLR versions are not synched with the .NET Framework version - also, CLR versions went straight from 2 to 4 (there was no CLR version 3). 


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Marked as answer by eryang Monday, September 13, 2010 9:30 AM
    Sunday, September 5, 2010 6:51 PM

All replies

  • It doesn't matter what you used to compile the app - what matters is what is running the app.  If the app is running under CLR version 2, then it won't be able to load CLR version 4 assemblies.

    For a test, check the value of "System.Environment.Version" when the app is running - you will probably see that for the cases where you are referencing a version 4 assembly that the app is actually running under CLR version 4, not 2.

     


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Saturday, September 4, 2010 2:17 PM
  • Hi David and thank you. I was wrong, my library was created using .NET 3.5 (not 4) and the web application that reference this library runs 2 CRL (checked with System.Environment.Version).
    Sunday, September 5, 2010 5:44 PM
  • Right - CLR version 2 can load libraries/assemblies using .NET 2, 3, and 3.5.

    For an app to load .NET Frameworki version 4 assemblies, the app needs to be running under CLR version 4.

    Note that this can be confusing since the CLR versions are not synched with the .NET Framework version - also, CLR versions went straight from 2 to 4 (there was no CLR version 3). 


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Marked as answer by eryang Monday, September 13, 2010 9:30 AM
    Sunday, September 5, 2010 6:51 PM
  •  

    Hi Thomas,

     

    I'm writing to check the issue status, does David's suggestion help? please feel free to let us know if you have any concern.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, September 7, 2010 10:33 AM