10

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?

3
  • If both your projects are using the full framework, why did you pull in a nuget package for http at all? Commented Oct 8, 2018 at 8:54
  • 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. Commented Oct 8, 2018 at 12:03
  • 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! Commented Aug 2, 2019 at 15:53

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I agree that you should be referencing System.Net.Http from the framework when targetting .NET Framework, like: <Reference Include="System.Net.Http" /> However, the package isn't necessarily broken if it pulls the http package into the closure since it could be for example targeting .NET Standard. If you have a repro project, do you mind logging an issue in github.com/dotnet/corefx with the repro project so that we could take a look at what is going on?
Had to remove the accepted answer because it doesn't change anything. After a full clean and rebuild, the warning comes again even though I am using the System.Net.Http from the full .net. All my projects target 4.7.2 full and use only a reference to the System.Net.Http from the .net assemblies, not from a nuget package any more. I don't have any assembly binding entries in web.config (or any other config) for this assembly either.
2

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.

1 Comment

Thank you for posting this. This seems to have helped my as well. When .NET 4.8 was installed, System.Net.Http.dll was located in my code's bin folder. I uninstalled the three .NET 4.8 things I saw under Apps & Features, removed the reference to System.Net.Http, and then added the reference back. Now the DLL is located under C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.