找不到类型或命名空间名称“Uri”:(包含 System.Uri 命名空间)
本文关键字:Uri 命名空间 包含 System 类型 找不到 | 更新日期: 2023-09-27 18:34:36
我正在通过遵循一个在线教程(构建Web应用程序(来学习 ASP.NET。问题是当我重用导师代码时,我卡在此错误上:
Error 1 The type or namespace name 'Uri' could not be found (are you missing a using directive or an assembly reference?)
我试图包含几个命名空间(如System.Uri(,但它们都不起作用。有人知道问题出在哪里以及我需要做什么来解决问题吗?
这是代码:
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);
}
}
你不能有using System.Uri;
,因为Uri
是一个类(在Visual Studio 2015之前不允许静态导入,我想你现在没有使用,即使在VS 2015中,它也会失败,因为Uri
不是静态类(
包括:
using System;
并删除
using System.Uri;
来自Microsoft Dochttp://msdn.microsoft.com/en-us/library/system.uri%28v=vs.110%29.aspx
要包含的引用是系统.dll默认情况下应该存在。 检查您是否没有错误地删除它。