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

只愿长相守 提交于 2020-01-03 16:59:45

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/49767979/method-not-found-system-net-http-httprequestmessage-system-web-http-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!