1

When I try to invoke api method I'm getting exception like

Method not found: 'Void System.Web.Http.Filters.HttpActionExecutedContext.set_Response(System.Net.Http.HttpResponseMessage)'.

ApiController:-

[System.Web.Http.HttpGet]
public HttpResponseMessage CheckUserAuthentication(string UserName, string Password)
{
    DomUserAuthentication objauthentication = new DomUserAuthentication();
    var res = Request.CreateResponse(HttpStatusCode.OK);
    /////Code here
    res.Content = new StringContent(json, Encoding.UTF8, "application/json");
    return res;
}

Here is my Webapi.config:-

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{Action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

Error details:-

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Method not found: 'Void System.Web.Http.Filters.HttpActionExecutedContext.set_Response(System.Net.Http.HttpResponseMessage)'.
</ExceptionMessage>
<ExceptionType>System.MissingMethodException</ExceptionType>
<StackTrace>
at SalesRevUp.CrossCutting.DataAPIErrors.OnException(HttpActionExecutedContext context) at System.Web.Http.Filters.ExceptionFilterAttribute.System.Web.Http.Filters.IExceptionFilter.ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken) at System.Web.Http.ApiController.<>c__DisplayClass8.<>c__DisplayClassa.<InvokeActionWithExceptionFilters>b__6(IExceptionFilter filter) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)
</StackTrace>
</Error>

screenshot

ekad
  • 14,436
  • 26
  • 44
  • 46

3 Answers3

0

As an alternative solution, You can make use of attribute routing https://learn.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing

    [Route("IntermediaryData/CheckUserAuthentication")]
    [System.Web.Http.HttpGet]
    public HttpResponseMessage CheckUserAuthentication(string UserName, string Password)
    {
        DomUserAuthentication objauthentication = new DomUserAuthentication();
        var res = Request.CreateResponse(HttpStatusCode.OK);
        /////Code here
        res.Content = new StringContent(json, Encoding.UTF8, "application/json");
        return res;
    }
Mb...R
  • 78
  • 3
-1

You Name of Get Method is not Proper Change name from "CheckUserAuthentication" to "GetCheckUserAuthentication"

 public HttpResponseMessage GetCheckUserAuthentication(string UserName, string Password)
        {
            DomUserAuthentication objauthentication = new DomUserAuthentication();
            var res = Request.CreateResponse(HttpStatusCode.OK);
            ///////Code here
            res.Content = new StringContent(json, Encoding.UTF8, "application/json");
            return Request.CreateResponse(HttpStatusCode.OK);
        }
Saineshwar Bageri - MVP
  • 3,851
  • 7
  • 41
  • 47
  • Thanks for your suggestion. But not work for me!. Please suggest if any different approach. – Suman Manna Jul 25 '18 at 15:03
  • Can you add entire API controller code snippet and without the core business logic – Saineshwar Bageri - MVP Jul 26 '18 at 05:41
  • I have try with following test method which is also not working. Here is code details:- [System.Web.Http.HttpGet] public HttpResponseMessage GetTest() { var res = Request.CreateResponse(HttpStatusCode.OK); string json = JsonConvert.SerializeObject("ABC"); res.Content = new StringContent(json, Encoding.UTF8, "application/json"); return res; } – Suman Manna Jul 26 '18 at 11:00
  • How are you calling this from Browser? – Shyam Jan 30 '20 at 09:15
-2

If this issue still active. I found the solution. The issue was with .Net framework. I've updated from 4.6 to 4.7 and the problem was solved.

tukhfatov
  • 11
  • 2