I am learning ASP.NET by following one online tutorial (building web application). Problem is when I reuse tutor code I stuck on this error:
Error 1 The type or namespace name 'Uri' could not be found (are you missing a using directive or an assembly reference?)
I tried to include several namespaces (like System.Uri) and none of them worked. Does someone knows where's the problem and what do I need to do to solve the problem?
Here is code:
using System.Collections.Generic;
using System.Net;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Web;
using System.Web.Http;
using System.Net.Http;
using System.Data.Entity.Infrastructure;
using System.Uri;
public HttpResponseMessage Post(Friend friend)
{
if (ModelState.IsValid)
{
db.Friends.Add(friend);
db.SaveChanges();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, friend);
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = friend.FriendId }));
return response;
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
}
You can't have using System.Uri;, since Uri is a class (and static import isn't allowed until Visual Studio 2015, which I suppose you are not using now, even in VS 2015, it would fail since Uri is not a static class)
Include:
using System;
and remove
using System.Uri;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With