.NET Visual Studio构建错误"存在此类型的另一个部分声明"

mal*_*pdx 5 .net visual-studio-2010 visual-studio-2008

我不是Windows世界中特别熟练的开发人员,我有一个需要解释的问题.我希望在我的无知中,我遗漏了一些明显的东西.

我发现自己不得不反编译预编译的.NET网站/应用程序.反射设法让我得到了我需要的c#CodeFile,我花了很多时间来改变所有.aspx引用,如下所示:

<%@ page language="C#" autoeventwireup="true" inherits="someclassname, App_Web_Z8sdf" %>
Run Code Online (Sandbox Code Playgroud)

这样的事情:

<%@ page language="C#" autoeventwireup="true" CodeFile="somefilename.aspx.cs" inherits="someclassname" %>
Run Code Online (Sandbox Code Playgroud)

并将aspx.cs文件移动到.aspx文件所在的目录中.

这让我能够在Visual Studio中以一种可编辑的形式加载项目.我在2010年和2008年都试过这个.

但是,现在我正在尝试构建这个项目.我得到的错误是:

"Missing partial modifier on declaration of type 'someclassname'; another partial declaration of this type exists"
Run Code Online (Sandbox Code Playgroud)

很公平.我知道类可以在多个地方声明,每个类都必须有"partial"关键字才能使其工作.所以我将partial关键字添加到发生错误的aspx.cs文件中的类定义中.这设法摆脱了该错误消息,并将其替换为

"The type 'someclassname' already contains a definition for 'some variable name".
Run Code Online (Sandbox Code Playgroud)

它显然表现得像某个地方的另一个类定义.我主要是一个unix管理员,我开始搜索项目中的所有文件,找到与相关类​​名相匹配的字符串,我发现它只有两个文件和两个文件.包含我引用的第一行的aspx文件,以及与其对应的包含类定义的aspx.cs文件.现在,我感到困惑.

我读了一些论坛帖子,表明Visual Studio会创建带有部分类的"设计器"文件,看起来很有希望,但我看不到这些设计器文件,即使我查看VS中的所有文件,当我看到磁盘上的目录,或者其他任何地方.显然,我错过了一些东西.也许我没有正确地从预编译站点重构?也许在web.config或我需要更改的其他文件中有一些设置?

任何帮助将不胜感激.

按要求提供someclass定义的通用版本

    using System;
    using System.Web;
    using System.Web.Profile;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class Some_Class_Name : Page, IRequiresSessionState
    {
        /// a bunch of variables defined like this
        protected HtmlForm form1;

       ///a bunch of protected methods defined similarly to this

        protected void LinkButtonReturn_Click(object sender, EventArgs e)
        {
            this.Session.Clear();
            base.Response.Redirect("Default.aspx");
        }

}
Run Code Online (Sandbox Code Playgroud)

更新 这似乎是从预编译站点转换回源的结果..aspx.cs文件包含控制字段定义(如果这是我将天真地称之为"变量定义"的正确术语),它们不应该,并且缺少它们应该具有的部分声明.疯狂地推测,似乎aspx文件实际上暗示了定义,因此aspx.cs文件不需要它们.非常感谢Dan Abramov和评论的其他人.

Dan*_*mov 2

我可能非常离题,但我怀疑编译器根据aspx代码本身生成部分类。如果这是真的,那么这些类显然会包含诸如form1.

我将删除所有控制字段声明,看看这是否有帮助。请注意,我不是 WebForms 人员,所以这是一个猜测。