13

I've got a project that targets .Net 4.0, and one of the referenced assemblies is .Net 4.5.

Until I installed .Net 4.5 this was working fine, however after the install I get five warnings regarding the targeted .Net version along these lines:

*The primary reference "xxxx.Library, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0"

And this:

The primary reference "Microsoft.TeamFoundation.Build.Workflow, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.TeamFoundation.Build.Workflow, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". Tests

Why does Visual Studio hate me? If it could compile before the update to 4.5, the targeted framework has not changed and it still works for a colleague on VS2010 with .Net 4 why am I being stuffed?

Dave
  • 316
  • 1
  • 2
  • 9
  • I'm having a similar issue, and seems to only happen with .NET Frameworks 4.5 installed. My project is targeting frameworks version 4.0 and the disassembly of my referenced DLL shows the assembly was built targeting frameworks version 4.0 as well. However, I am getting an invalid error that the referenced DLL was built targeting version 4.5 of the frameworks. http://stackoverflow.com/questions/18360561/the-primary-reference-could-not-be-resolved-because-it-was-built-against-a-highe – Dude0001 Aug 21 '13 at 15:00

2 Answers2

13

The error message explains the problem - a .NET 4 app can't reference a .NET 4.5 dll. Change your app to .NET 4.5 as well, or change the dll back to .NET 4.

thecoop
  • 45,220
  • 19
  • 132
  • 189
  • Why did this work prior to the update to 4.5 then? All compiles happily and no warnings or errors? – Dave May 31 '13 at 11:48
  • As in, if I uninstall .Net 4.5, this error goes away and I can compile the project...? – Dave May 31 '13 at 11:49
  • 2
    Except maybe not obvious since the question suggests that the assembly has always been 4.5 and worked previously but once .NET 4.5 was installed it for some reason stopped allowing it. – Chris May 31 '13 at 11:50
  • 1
    There are no warnings from VS about 'unknown framework version' or something like that? I suspect it was actually compiling the .NET 4.5 dll as .NET 4, as .NET 4.5 wasn't available. Either way, this should not work in the first place. If it did, it was a fluke. Change the app framework if you do want it to reliably work. – thecoop May 31 '13 at 11:50
  • 3
    I'd change the answer you gave since the current one is not really the answer to the question. – Joetjah May 31 '13 at 11:51
  • @thecoop: The .NET4.5 assembly is referred to as a referenced assembly. I assume this means it is an external assembly that isn't compiled in the build process so your suggestion that it is being built as .NET 4 seems out of the blue. – Chris May 31 '13 at 11:54
5

It's because for reasons best known to Microsoft, the .NET Framework 4.5 is an in-place update that replaces your .NET Framework 4 files (rather than a side-by-side installation). If you look in C:\Windows\Microsoft.NET, you won't find a 4.5 folder--it replaced the files in your 4.0 folder.

So the reason it compiled before is that the dll was a .Net 4.0 dll then. Now it's been replaced by a 4.5 one.

Reg Edit
  • 6,719
  • 1
  • 35
  • 46