Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace name 'Uri' could not be found: (System.Uri namespace is included)

Tags:

c#

asp.net

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);
            }
    }
like image 618
jureispro Avatar asked Jan 25 '26 17:01

jureispro


1 Answers

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;
like image 199
Habib Avatar answered Jan 28 '26 10:01

Habib