Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Higher .NET Framework Version for System.Net.Http than Project

I have a project which references System.Net.Http 4.2.0.0 (I recently updated to the newest nuget package). Now I get this warning during compilation from ASPNETCOMPILER (although I use System.Net.Http in a class library project which is reference by my web project):

The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: MyClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. Warning in MyWebProject, ASPNETCOMPILER

Both my class library and web project are using .Net 4.7.2, so no higher version to go to. The web project is using MVC with System.Web.Mvc 5.2.6.

What causes this warning and how can I get rid of it?

like image 209
Vladimir Avatar asked Oct 08 '18 08:10

Vladimir


People also ask

What is the latest version of System Net HTTP?

The latest version of System. Net. Http on nuget is 4.3.

How do I upgrade .NET version?

NET Framework version. To update the target framework for all projects, right-click on the project (one by one), click properties, and from the “Application” tab change the target framework to the desired one as in the following screenshot and select “Yes” in the popup that is displayed after the framework is changed.


2 Answers

If you are using the full .NET framework, drop the Nuget reference altogether and reference System.Net.Http normally, it's already included with the full framework.

If that reference is the result of a third-party nuget package, please inform them that their package is broken for full framework use. They should add that as a reference instead of a package reference if they want to support the full framework.

like image 66
nvoigt Avatar answered Sep 20 '22 11:09

nvoigt


I used to have the same problem, but today it has downed upon me. My code targets .NET 4.7.2, but I have also .NET 4.8 installed on my machine. So, apparently, AspNetCompiler notices that my code takes some dependencies from the GAC, which correspond to .NET 4.8, which has a higher version that the one my code targets - 4.7.2. Hence the error message.

Uninstalling .NET 4.8 removed the messages.

Your issue could have the same root cause - your local machine has .NET Framework of the higher version than the one you target. Either uninstall it or modify the references in the web.config that control compilation of the embedded C# code.

like image 20
mark Avatar answered Sep 20 '22 11:09

mark