The primary reference could not be resolved because it was built against a higher version of the .NET framework than the currently targeted framework
Asked Answered
B

4

23

I am trying to build a project that references a 3rd party SlingshotClient.dll. The project builds fine on other developers workstations. However, I am getting the error below. One difference that I could imagine is contributing to my issue is that I also have VS 2012 and .NET Frameworks 4.5 installed on my machine. I believe the other developers that can build this successfully, don't have those installed.

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3274: The primary reference "SlingshotClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb5a8745472e181a, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher versio n than the currently targeted framework ".NETFramework,Version=v4.0".

The error seems to be saying that our project targets the framework version 4.0 (which is correct), but the referenced SlingshotClient.dll was built targeting framework version 4.5. When I look at the SlingshotClient.dll in the dissembler, it looks to me that the assembly was built targeting framework version 4.0

h

Bonar answered 21/8, 2013 at 14:43 Comment(2)
You need to scroll down and look at the TargetFrameworkAttributeDress
@HansPassant you are correct. The TargetFrameworkAttribute a little further down and says 4.5. Another article I read said I needed to check the version of mscorlib referenced. This explains it, although, I'm still surprised it compiles without complain on a machine with only .NET Framework 4.0. If you want to post your comments as an answer to this question, I'll have you credit for the correct answer.Bonar
B
25

Apparently if you have only .NET Frameworks 4.0 installed, you can add as a reference a .NET assembly that targets 4.5 to a project that targets .NET 4.0. This will compile and run with no errors.

As soon as you install .NET Frameworks 4.5, compile will fail. The solution is to target your project for .NET Framework 4.5 or get a version of the referenced assembly that targets .NET 4.0.

.NET 4.5 is a drop in replacement for 4.0. 4.0 doesn't know anything about 4.5, and I assume it is just looking at the first digit of the version number which for 4.0 or 4.5 is the same, so it is allowed to compile. As soon as you install 4.5, your 4.0 projects are compiled using the 4.5 Frameworks and it now knows about 4.5 and complains.

Bonar answered 5/3, 2014 at 17:57 Comment(0)
C
4

As a workaround, you can add the following to your .csproj file within the <Project> element.

<PropertyGroup>
<ResolveAssemblyReferenceIgnoreTargetFrameworkAttributeVersionMismatch>true</ResolveAssemblyReferenceIgnoreTargetFrameworkAttributeVersionMismatch>
</PropertyGroup>

Be aware that while this does make the compilation errors go away, those errors are there for a reason and ignoring them blatantly can absolutely cause issues when the binary you are referencing tries to perform code that does not work on your lower version of .NET.

Reference

Catherine answered 30/12, 2020 at 0:58 Comment(1)
Yeah, that's a real problem. What if we lower one and realize what code won't perform in the lower version.Peerage
U
0

I resolved this issue by changing the framework to match the framework that the project is being built against. resolution explained here

Unprofitable answered 30/1, 2023 at 11:57 Comment(0)
A
0
  1. Download+Install NETFramework4.5
  2. Open *.csproj file
  3. Find your framework version (Ctrl+F -> 4.0)
  4. Replace to 4.5
  5. Save
  6. Start project enter image description here
Alister answered 18/5 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.