错误CS0103:当前上下文中不存在名称“HttpUtility”

时间:2012-10-18 10:24:21

标签: c# mono opensuse

我收到此错误“错误CS0103:当前上下文中不存在名称”HttpUtility“ 当我尝试使用“$ mcs file.cs”编译我的c#文件时。我添加了“使用System.Web”,我使用单声道框架在Suse 12.1上运行它。我是C#的新手,我正在遵循这里的教程http://www.codeproject.com/Articles/9407/Introduction-to-Mono-Your-first-Mono-app

这是我file.cs中的代码

using System;
using System.Net;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;

namespace Dela.Mono.Examples
{
        class GoogleSearch
         {
                static void Main(string[] args)
                 {
                        Console.Write("Please enter a string to search google for:");
                        string searchString = HttpUtility.UrlEncode(Console.ReadLine());

                        Console.WriteLine();
                        Console.Write("Please wait....\r");

                        //Query google
                        WebClient webClient = new WebClient();
                        byte[] response =     webClient.DownloadData("http://www.google.com/search?&num=5&q=" + searchString);


                        //Check reponse results
                        string regex = "g><a\\shref=\"?(?<URL>[^\">]*)[^>]*>(?<Name>[^<]*)";
                        MatchCollection matches = Regex.Matches(Encoding.ASCII.GetString(response), regex);

                        //output results
                        Console.WriteLine("===== Results =====");
                                 if(matches.Count > 0)
                                 {
                                        foreach(Match match in matches)
                                        {
                                                 Console.WriteLine(HttpUtility.HtmlDecode(
                                                        match.Groups["Name"].Value) +
                                                        " - " + match.Groups["URL"].Value);
                                        }
                                 }
                                 else
                                 {
                                        Console.WriteLine("0 results found");
                                 }
                } 
        }
}

可能是什么问题以及如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

如您所链接的文章所述,请尝试使用以下内容进行编译:

$ mcs file.cs -r System.Web.dll