I'm writing some authentication logic in my Web API 2 app and I'm getting the error in the subject line. At first I was just returning Unauthorized() but then I got the error in the subject line. When I revisited the code I noticed that Intellisense didn't show a parameterless constructor for Unauthorized so I'm not sure why that didn't trigger a build error. It looks like the contstructor only accepts a collection of AuthenticationHeaderValues. So then I updated my implementation to simply pass null for this parameter but I'm still getting the error in the subject line.
I'm not getting a compiler or runtime error saying that the parameter is missing or required, only that the method is not found, which seems weird. Any idea what the issue might be? Can you provide a basic working example with a parameter that I can pass or does this appear to be a different issue?
UPDATE
I followed the instructions in the answer below but I'm still getting the same error. Here's the full stack trace:
"{\"Message\":\"An error has occurred.\",\"ExceptionMessage\":\"Method not found: 'System.Web.Http.Results.UnauthorizedResult System.Web.Http.ApiController.Unauthorized(System.Collections.Generic.IEnumerable`1<System.Net.Http.Headers.AuthenticationHeaderValue>)'.\",\"ExceptionType\":\"System.MissingMethodException\",\"StackTrace\":\" at SecurityApi.Controllers.AuthenticationController.<Authenticate>d__3.MoveNext()\\r\\n at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\\r\\n at SecurityApi.Controllers.AuthenticationController.Authenticate(UserCredentials userCredentials)\\r\\n at lambda_method(Closure , Object , Object[] )\\r\\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass12.<GetExecutor>b__8(Object instance, Object[] methodParameters)\\r\\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\\r\\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()\"}"