Can .NET 4.0 code interoperate with .NET 2.0 code?

后端 未结 2 1848
独厮守ぢ
独厮守ぢ 2021-02-01 17:21

Are there compatibility barriers with a .NET 4.0 assembly calling code in a .NET 2.0 assembly? And vice versa?

More specifically, I\'m investigating an upgrade to Visua

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 18:23

    The CLR, in .NET 4, can consume .NET 2 assemblies and use them properly.

    If you want your .NET 2 application to be able to load .NET 4 assemblies, you'll need to configure it differently. By setting the requiredRuntime to .NET 4, and the legacy load policy, you should be able to force the .NET 2 application to load using CLR 4, which would allow your .NET 4 assemblies to be used.

    Setup your app.config file to include:

    
    
      
        
      
    
    

    That being said, in a situation like this, I'd recommend just using VS 2010 and targetting .NET 3.5 instead of .NET 4. This would compile your assemblies for CLR 2, and avoid this issue entirely.

提交回复
热议问题