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?
The latest version of System. Net. Http on nuget is 4.3.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With