2
votes

I have a MVC 3 application that targets .net 4.0 It has a dozen or so projects also targeting .net 4.0

I have created a new project for the solution targeting .net 4.5 that uses reflection (there are a couple of nice bits of functionality in 4.5 that I want to use). When I try to compile I get an error saying that the 'type or namespace (new 4.5 proj) could not be found, are you missing a directive or an assembly reference'.

Is it possible to have a reference to an assembly targeting .net 4.5 in a project that targets 4.0?

3
In theory I would say you could, because .Net 4.5 is a drop in replacement for .Net 4.0 so the runtimes are the same. I would recommend against it because obviously you're running the risk of calling code that doesn't exist in your 4.5 project. Is it a BCL feature you want in 4.5 or a language feature?CodingGorilla
The compiler is applying the two-by-four to your forehead. If you think it is wrong then do try to imagine what would happen when your code calls a method that's only available in .NET 4.5 but runs on a machine that has 4.0 installed. Smack.Hans Passant
CodingGorilla - it's a BCL feature, reflection of attributes seems to be a bit nicer and has a few more helper functionsatreeon

3 Answers

1
votes

Is it possible to have a reference to an assembly targeting .net 4.5 in a project that targets 4.0?

No. It shouldn't be. There could be some features that are used in .Net 4.5 assembly which are not part of .Net 4.0, In that particular case, it should fail.

1
votes

I guess you could just set your project to .net 4.5, but if you would like to keep it as 4.0, take a look at this link might help you

0
votes

Yes, it is possible. Just open the .csproj file for the .Net 4.0 assembly giving the assembly load error in a text editor and set this for the .Net 4.5 assembly reference:

      <SpecificVersion>True</SpecificVersion>