[英]CS0246 visual studio community edition 2015 missing reference?
I have a "windows 10 pro" and a fresh install of "visual studio community edition 2015" installed.我安装了“windows 10 pro”和全新安装的“visual studio Community Edition 2015”。
I do a new project console application and call it ftptest then copy and paste the code from here:我创建了一个新的项目控制台应用程序并将其命名为 ftptest,然后从此处复制并粘贴代码:
https://msdn.microsoft.com/en-us/library/ms229716%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/ms229716%28v=vs.110%29.aspx
using System;
using System.IO;
using System.Net;
namespace ftpcheck
{
public class Program
{
public void Main(string[] args)
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("anonymous", "janeDoe@contoso.com");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);
reader.Close();
response.Close();
}
}
}
And try to build it just to see what it does.并尝试构建它只是为了看看它能做什么。
I get a lot of:我得到了很多:
CS0246 The type or namespace name 'FtpWebRequest' could not be found (are you missing a using directive or an assembly reference?)
CS0246 找不到类型或命名空间名称“FtpWebRequest”(是否缺少 using 指令或程序集引用?)
CS0246 The type or namespace name 'NetworkCredential' could not be found (are you missing a using directive or an assembly reference?)
CS0246 找不到类型或名称空间名称“NetworkCredential”(是否缺少 using 指令或程序集引用?)
How can i add that missing reference?我如何添加缺少的参考?
If you take a look on msdn, you will see the reference that you have to add: 如果您看一下msdn,将看到必须添加的参考:
https://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest(v=vs.110).aspx https://msdn.microsoft.com/zh-CN/library/system.net.ftpwebrequest(v=vs.110).aspx
Namespace: System.Net
Assembly: System (in System.dll)
answered with a comment by hans passant: 汉斯·帕兰特(hans passant)的评论回答:
My crystal ball says that you are using the wrong project template to get started. 我的水晶球说您使用错误的项目模板开始。 Use Visual C# > Windows > Classic Desktop > Console Application.
使用Visual C#> Windows>经典桌面>控制台应用程序。 And you somehow lost the static keyword on the Main() method.
而且您以某种方式丢失了Main()方法上的static关键字。 – Hans Passant Nov 26 '15 at 20:48
–汉斯·帕桑(Hans Passant),2015年11月26日在20:48
include: using System.Net;包括:使用 System.Net; in your references section
在你的参考部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.