Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Website Project builds but errors on publish

We have a .NET 4 Website Project created using Visual Studio 2013, it references the System.Net.Http .dll.

This is the line in web.config that loads the .dll:

<add assembly="System.Net.Http, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

The project builds fine but when we try to “Publish Web Site” it gives the following error:

The type or namespace name ‘Http’ does not exist in the namespace ‘System.Net’ (are you missing an assembly reference?)

It looks like the assembly might be loading from the GAC, we have tried putting the assembly in the application’s BIN folder but this makes no difference – it is still showing as a GAC reference on the project property pages.

We have also tried adding:

<runtime>
    <assemblyBinding>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <codeBase version="1.0.0.0" href="/bin/System.Net.Http.dll"/>
      </dependentAssembly>
    </assemblyBinding>

As suggested here: Could not load file or assembly System.Web.Http.WebHost after published to Azure web site

But this does not seem to work either.

We have changed the Target Framework to 3.5 and 4.5 with no effect.

We have tried publishing from several different machines.

EDIT: We have tried the nuget package suggest in RobAda and it hasn't had the desired effect, we are still getting errors.

like image 330
Mack Avatar asked Nov 24 '15 09:11

Mack


2 Answers

I have seen the same problem on a friends app, we needed to dig around quite a bit but eventually found that you need to install this nuget package:

https://www.nuget.org/packages/Microsoft.Net.Http

You will then need to add the reference to System.Net.Http for it to not produce the stated error.

like image 182
RobAda Avatar answered Nov 15 '22 22:11

RobAda


Sound like you are trying to shoehorn something where it does not/cannot fit.

One possible architectural approach would be to separate the functionality out into a solution.

If time constraints are an issue and this is a possibility, it may be the solution to your problems.

Long term though: It would be worth ensuring that you keep up to date with the times as you will get more issues like this as time moves on, of course this must be approach pragmatically...

like image 43
VixterJ Avatar answered Nov 15 '22 21:11

VixterJ