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

Posted

技术标签:

【中文标题】错误 CS0103:当前上下文中不存在名称“HttpUtility”【英文标题】:error CS0103: The name `HttpUtility' does not exist in the current context 【发布时间】:2012-10-18 10:24:21 【问题描述】:

我收到此错误“错误 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");
                                 
                 
        

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

【问题讨论】:

您的目标是客户资料吗?尝试改变它 是的,而且似乎 System.Web 在那里不可用。那么考虑到我正在使用 suse linux,我该如何解决。 是的,我正在努力解决这个问题。谢谢。 @roykasa 添加-r System.Web.dll 解决了你的问题吗? @Nacereddine 继续发帖作为答案 【参考方案1】:

如您链接到的文章中所述,请尝试编译:

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

【讨论】:

以上是关于错误 CS0103:当前上下文中不存在名称“HttpUtility”的主要内容,如果未能解决你的问题,请参考以下文章

CS0103: 当前上下文中不存在名称“DataHelper”

如何解决 Stripe xamarin 绑定错误? (CS0103 当前上下文中不存在名称“开始”)

CS0103 - 当前上下文中不存在名称“GetListFromCVS”[关闭]

CS0103:当前上下文中不存在名称“ClassName”

ERROR CS0234名称空间名称“编码”不存在

using System.Configuration显示灰色,当前上下文中不存在名称“ConfigurationManager”