For some reason, Request.CreateResponse
is now \"red\" in VS2012 and when I hover over the usage the IDE says
Cannot resolve symbol \'Cre
Because this extension method lives in System.Net.Http
, you just need to include it in your usings statements.
using System.Net.Http;
You need to add a reference to System.Net.Http.Formatting.dll
. The CreateResponse
extension method is defined there.
You can use
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.Gone)
instead of
Request.CreateResponse(HttpStatusCode.Gone)
This is because you have to do:
namespace GOCApi.Controllers
{
[RoutePrefix("Courses")]
public class CoursesController : ApiController
{
private ICoursesRepository _coursesRepository { get; set; }
public CoursesController(ICoursesRepository coursesRepository)
{
_coursesRepository = coursesRepository;
}
[GET("{id}")]
public HttpResponseMessage Get(int id)
{
var course = _coursesRepository.GetSingle(id);
if (course == null){
return this.Request.CreateResponse(HttpStatusCode.NotFound, "Invalid ID");
}
return this.Request.CreateResponse(HttpStatusCode.OK, course);
}
}
}
Note the this
.
In my case the compiler now gets it.
Saw the example here
This a known issue with VB.NET and Request.CreateResponse.
There is a workaround: Missing request.CreateResponse in vb.net Webapi Projects
Add a reference to System.Web.Http
to the project. Then add
Using System.Web
to the top of the cs file.