I have verified that the file which has the HttpResponseMessage
as return type is set to "compile" like they said here: Why I cannot use HttpResponseMessage class?
I have migrated from packages.config to packagereference (nuget) and have a .net 4.7.2 mvc project containing webapi. It worked before, but after a few Nuget updates it does not anymore. I have had issues with system.web.http and the build in 4.0.0 version in the framework and the 4.x nuget which is newer.
My issue seems related to https://github.com/Microsoft/dotnet/issues/737 but I am not sure.
I have also tried this https://stackoverflow.com/a/50095678/169714
so here is that part of my web.config:
<system.web>
<globalization fileEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>
<compilation debug="true" targetFramework="4.7.2">
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.7.2"/>
Switching back to 4.7.1 makes intellisense give the suggestion to add using System.Net.Http;
instead of using System.Web.Http;
and does seem to fix it. But why?
So I can post the "answer" right now: revert to 4.7.1. So the question is: why does that fix it?
edit
I have manually moved from packages.config to packagereference and found this: Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies
It's says that there should be a migrate option. But I did not see it and had the .config file removed. I have reinstalled most of the nuget packages, but I am stuck at System.Runtime, Version=4.2.1.0
even when I have the 4.3.0 nuget installed. Normally VS gives me in the debug info an option to double click and redirect assembly bindings in the web.config. But it's not there, so perhaps a manual addition?
I also tried to add
<ItemGroup>
<PackageReference Include="Legacy2CPSWorkaround" Version="1.0.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
to all other nuget's packagereferences. but that did not help either. I also tried to add the NetStandard.Library nuget, but that did not help either...
adding
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.3.0" />
</dependentAssembly>
this did not help either. there was no system.runtime in the web.config before. It's still trying to find System.Runtime, Version=4.2.1.0
.
No packages nor bindingRedirects should be required on .NET 4.7.2. Simply referencing System.Net.Http and “using System.Net.Http” should make HttpResponseMessage available.
This issue is related: https://github.com/dotnet/sdk/issues/2221
Please install Visual Studio 2017 Update 15.8. It will ensure that the project files and dependencies will work for your scenario.
See: https://blogs.msdn.microsoft.com/visualstudio/2018/08/14/visual-studio-2017-version-15-8/