9

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)

1
  • I cannot repro your issue on my VS 2012 MVC4 Web API project. What exception are you getting after adding the reference to System.Net.Http to your web.config? Commented Oct 12, 2012 at 21:47

1 Answer 1

28

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.

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

4 Comments

I've been fighting this stupid issue forever and the above fixed it... thanks so much
I have spent all day on this error, and only this post fixed it. MmmmWAH!
Worked for me but I needed oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"
Adding the entry under the <compilation...> was what made it working for me. I had upgraded System.Net.Http amongst other dlls, that had broken it. Thanks!

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.