C# 解决编译器错误 CS1519:类、结构或接口成员声明中的无效标记“,”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/355876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:19:26  来源:igfitidea点击:

Resolving compiler error CS1519: Invalid token ',' in class, struct, or interface member declaration

c#.netasp.net

提问by gilles27

I'm working on an ASP .NET 2.0 site which uses a Web Application project file, and therefore compiles to a dll rather than deploying the source code as you do with the older style Web Site projects.

我正在处理一个 ASP .NET 2.0 站点,该站点使用 Web 应用程序项目文件,因此编译为 dll,而不是像处理旧式 Web 站点项目那样部署源代码。

The site works fine on my test server (Windows Server 2003 R2, IIS6) when it runs in the root of a website. However I need to run it under a virtual directory instead. When I switch over to that, I get the following error on browsing to any of the pages in the site

当它在网站的根目录中运行时,该站点在我的测试服务器(Windows Server 2003 R2、IIS6)上运行良好。但是我需要在虚拟目录下运行它。当我切换到那个时,在浏览到站点中的任何页面时出现以下错误

CS1519: Invalid token ',' in class, struct, or interface member declaration

CS1519:类、结构或接口成员声明中的无效标记“,”

The error message goes onto tell me the line number and code file, however the code file is under the Temporary ASP .NET files folder and when I try to find it, it's not there.

错误消息继续告诉我行号和代码文件,但是代码文件在 Temporary ASP .NET files 文件夹下,当我尝试找到它时,它不在那里。

As such I'm unable to work out which page is causing the issue although I suspect it could be the master page, if this error occurs on all pages. Has anyone else seen this before or found a solution?

因此,我无法确定哪个页面导致了问题,尽管我怀疑它可能是母版页,如果此错误出现在所有页面上。有没有其他人以前见过这个或找到解决方案?

采纳答案by gilles27

Turns out the problem was related to inheriting the config settings of the site above mine in the virtual hierarchy.

原来问题与在虚拟层次结构中继承我上面站点的配置设置有关。

That site uses a custom profile whose properties are defined under system.web, profile, properties in the config file. The type of one of the properties was specified in the "Namespace.ClassName, AssemblyName" format.

该站点使用自定义配置文件,其属性在配置文件中的 system.web, profile, properties 下定义。属性之一的类型以“Namespace.ClassName, AssemblyName”格式指定。

When I removed the ", AssemblyName" from the end, the issue resolved itself, because I'd got rid of the comma that was the invalid token.

当我从末尾删除“,AssemblyName”时,问题自行解决,因为我去掉了无效标记的逗号。

I can only assume that, when ASP .NET compiles pages at runtime, it must have been compiling the profile class too, and using the property definitions in the config file during the code generation.

我只能假设,当 ASP .NET 在运行时编译页面时,它也必须编译配置文件类,并在代码生成期间使用配置文件中的属性定义。

回答by Marc Gravell

It sounds like you haven't set the virtual as an applicationin IIS, or it is running the wrong version of ASP.NET (i.e. 1.1, when it should be 2.0.blah).

听起来您没有在 IIS中将虚拟设置为应用程序,或者它运行的 ASP.NET 版本错误(即 1.1,而它应该是 2.0.blah)。

The virtual should have the cog icon in the IIS view, and in the properties pane, must have an application name.

虚拟应该在 IIS 视图中具有齿轮图标,并且在属性窗格中,必须具有应用程序名称。

回答by noemi

namespace Rectangle
{
    class Name
    {
        int length1;
        int width1;
        int sum;

        Console.Write("Enter the length: ");
            length = int.Parse(Console.ReadLine());

        Console.Write("Enter the width: ");
            width = int.Parse(Console.ReadLine());

        sum = length1* width1;

        Console.WriteLine($"Sumis {sum}");

    }
}

回答by Lucien

My group mates and I kept having the same issue. The thing is that when you copy a code from somewhere and paste it in Visual Studio, sometimes it adds dots between lines. They are not displayed in Visual Studio, but compiler keeps giving you an error messages, which is in fact frustrating. To get rid of them, paste that code snippet in some online compiler. In online compilers those dots are displayed, so you can easily delete them, and then copy & paste the neat code.

我和我的队友一直有同样的问题。问题是,当您从某处复制代码并将其粘贴到 Visual Studio 中时,有时会在行之间添加点。它们不会显示在 Visual Studio 中,但编译器不断向您提供错误消息,这实际上令人沮丧。要摆脱它们,请将该代码片段粘贴到某个在线编译器中。在在线编译器中,会显示这些点,因此您可以轻松删除它们,然后复制并粘贴整洁的代码。