9
votes

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?

2
If both your projects are using the full framework, why did you pull in a nuget package for http at all?nvoigt
I did so because previously my projects were using 4.6.1 and it referenced System.Net.Http 4.0.0.0 while another package was using 4.1.1.1 which was causing an error and the suggestion was to update to the newest one. Now after updating to 4.7.2 the newer version is available.Vladimir
Hi @Vladimir, were you able to solve this somehow? I have just migrated all my projects to .NET 4.8 and I started getting this, exactly like you. I'm referencing the framework DLL, and I have checked everything. Still no clue. Thanks!LucasMetal

2 Answers

5
votes

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.

1
votes

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.