user1741945
user1741945

Reputation: 103

ASP.net Web API and System.Net.Http

Following the example in this article: http://blogs.msdn.com/b/yaohuang1/archive/2012/05/21/asp-net-web-api-generating-a-web-api-help-page-using-apiexplorer.aspx

I've set up everything to provide documentation for my Web API project but I'm running into an issue. When I try to use @api.HttpMethod I get the error he describes about halfway through the article. He says you have to manually add a reference to the System.Net.Http, Version=2.0.0.0 assembly in the web.config (even though it's in the References folder by default), but if you follow his example of adding the assembly the traditional way through the tag in web.config..... well you'll find that is no longer a valid tag in 4.5 and everything is done through AssemblyRedirects. I tried that but to no avail. Anyone having this issue or know how to help with the change in web.config? Did I miss a meeting?

Visual Studio 2012 MVC4 Web API project (not from Nuget, the final release shipped with VS2012)

Upvotes: 9

Views: 7875

Answers (1)

tugberk
tugberk

Reputation: 58494

Add the below configuration inside your Web.config file under <system.web> node (assuming your app runs on .NET 4.5, targetFramework attribute is set to 4.5):

<compilation targetFramework="4.5">
  <assemblies>
    <add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </assemblies>
</compilation>

Also add the below one at the root level under <configuration> node:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

This should solve your problem.

Upvotes: 28

Related Questions