Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Api Request.CreateResponse HttpResponseMessage no intellisense VS2012

For some reason, Request.CreateResponse is now "red" in VS2012 and when I hover over the usage the IDE says

Cannot resolve symbol 'CreateResponse'

Here is the ApiController Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Filters;
using GOCApi.Attributes;
using GOCApi.Models;
using GOCApi.Models.Abstract;
using AttributeRouting;
using AttributeRouting.Web.Http;

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 Request.CreateResponse(HttpStatusCode.NotFound, "Invalid ID");
            return Request.CreateResponse(HttpStatusCode.OK, course);
        }
    }
}

Granted, the code does compile and works, it's just really annoying seeing all the "red" on my screen. Also, the intellisense doesn't work now when I type Request.CreateResponse. This also used to work, but I started developing other parts to my API and just came back to building controllers so I do not know what happened.

Any thoughts?

like image 397
crizzwald Avatar asked Apr 04 '13 15:04

crizzwald


3 Answers

You need to add a reference to System.Net.Http.Formatting.dll. The CreateResponse extension method is defined there.

like image 155
Rafael Romão Avatar answered Nov 12 '22 08:11

Rafael Romão


Because this extension method lives in System.Net.Http, you just need to include it in your usings statements.

using System.Net.Http;
like image 36
scidec Avatar answered Nov 12 '22 08:11

scidec


You can use

 HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.Gone)

instead of

 Request.CreateResponse(HttpStatusCode.Gone)
like image 8
Diwakar Sharma Avatar answered Nov 12 '22 09:11

Diwakar Sharma