Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading an assembly targeted for .NET 4.5 on a .NET 4.0 app domain

Assuming the system has .NET 4.0 and .NET 4.5 installed.

Is it possible to load and work with a .NET 4.5 assembly from an assembly written targeting .NET 4.0?

Simply put, can I call Assembly.Load from .NET 4.0 code to load a .NET 4.5 targeting assembly?

like image 703
Madushan Avatar asked Sep 27 '12 23:09

Madushan


1 Answers

Assuming a system as .NET 4.0 and .NET 4.5:

As stated in marcgravell's blog linked by sehe

4.5 is an in-place over-the-top install on top of 4.0, in the GAC; once you have installed 4.5, 4.0 runs with the 4.5 assemblies

Then calling Assembly.Load from a .NET code targeting 4.0 (compiled by a 4.0 compiler), will actually run in using the 4.5 framework implementation, so I don't see any reason why it couldn't load a 4.5 assembly.

margravell notes that problems occur when you try to run .NET 4.5 compiled code on a system with only 4.0 installed, as the implementation of the yield return/break iterators causes a missing method reference. But this shouldn't affect you.

like image 118
MerickOWA Avatar answered Sep 23 '22 07:09

MerickOWA