WebSite / .net Framework 4.6.1 / VS2017
如果我右键单击项目/添加/添加新项/ Visual c#/通用处理程序 然后单击添加,然后VS2017创建一个.ashx文件。该文件将编译并运行正常,但编辑器视图在错误列表窗口中显示错误。
清洁的溶液并重建=>不变
已清理解决方案并重新启动vs2017并重建=>不变
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
我希望它不会给出任何错误,但它会给出:
Severity Code Description Project File Line Suppression State
Error CS1022 Type or namespace definition, or end-of-file expected Miscellaneous Files C:\Users\xxx\Handler.ashx 1 Active
Error CS1646 Keyword, identifier, or string expected after verbatim specifier: @ Miscellaneous Files C:\Users\xxx\Handler.ashx 1 Active
Error CS1002 ; expected Miscellaneous Files C:\Users\xxx\Handler.ashx 1 Active
Error CS0116 A namespace cannot directly contain members such as fields or methods Miscellaneous Files C:\Users\xxx\Handler.ashx 1 Active
Error CS1022 Type or namespace definition, or end-of-file expected Miscellaneous Files C:\Users\xxx\Handler.ashx 1 Active
Error CS1529 A using clause must precede all other elements defined in the namespace except extern alias declarations Miscellaneous Files C:\Users\xxx\Handler.ashx 2 Active
Error CS1529 A using clause must precede all other elements defined in the namespace except extern alias declarations Miscellaneous Files C:\Users\xxx\Handler.ashx 3 Active