8

I have created One Filter Attribute

public class AuthFilterAttribute : System.Web.Http.Filters.ActionFilterAttribute { public AuthFilterAttribute() { } public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { } } 

I have registered this filter inside the global.asax.cs.

When I am trying to call my web API using Postman it is showing the error:

Method not found: 'System.Net.Http.HttpRequestMessage System.Web.Http.Controllers.HttpActionContext.get_Request()'.

My project target framework is 4.6.1 and the System.Net.Http version is 4.2.0.0

My API looks like this:

[AuthFilter] public class ScheduleApiController : BaseApiController { [Route("api/v1/schedules")] [HttpGet] public IHttpActionResult GetSchedules() { } } 

I know this question has been asked before but none of the solutions worked for me.

Please help me to resolve this issue.

6
  • Please add the url with which your are trying to call from postman Commented Apr 11, 2018 at 6:51
  • I am trying to run in the local host Url is :localhost:54252/api/v1/schedules Commented Apr 11, 2018 at 7:11
  • Try removing [AuthFilter] .an make sure you have config.MapHttpAttributeRoutes(); in WebApiConfig Commented Apr 11, 2018 at 7:21
  • You can also try the default help that is available when you create new web api project.Try accessing localhost:54252/help Commented Apr 11, 2018 at 7:25
  • 2
    Do you have this file also at this location:C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib If so, try deleting/renaming it. Commented Apr 11, 2018 at 8:12

2 Answers 2

29

Are you referencing a .NET Standard Library by any chance. I ran into this problem and solved it with a Binding Redirect:

 <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.2.0.0" /> </dependentAssembly> 
Sign up to request clarification or add additional context in comments.

4 Comments

This worked for me, I was using Standard 2.0 for dlls and Framework 4.7 for web api.
Saved my bacon!
WTF why didn't publish wizard automatically added it in web.config?
After 6 hours this fixed the issue
0

You could try to enable the auto-generate bindings. Right Click on your project --> Properties --> Application

Tick that

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.