【问题标题】:error cs1729 doesnt contain a constructor错误 cs1729 不包含构造函数
【发布时间】:2013-06-03 21:20:56
【问题描述】:

相同的代码在 1 个项目中有效,而在其他项目中无效。任何其他方式来写这个。 我得到的错误是错误 CS1729:“评估”不包含带有 12 个参数的构造函数。当我复制到 diff 项目中时,它编译并且运行良好。尝试清理临时 asp.net 文件,但没有帮助。

public class Assessment
{ 
   public Assessment(Guid assessmentId,string applicationId,string assessmentType,   Guid requestedBy,DateTime requestedDate,Guid assessmentOwner,string applicationToTest,
bool isCompleted,DateTime dateScheduled,DateTime datePerformed, GuidperformedBy,       string uri)
   {
        this.AssessmentId = assessmentId;      this.ApplicationId = applicationId;
        this.AssessmentType = assessmentType;  this.RequestedBy = requestedBy;
        this.RequestedDate = requestedDate;    this.AssessmentOwner = assessmentOwner;
        this.ApplicationToTest = applicationToTest; this.IsCompleted = isCompleted;
        this.DateScheduled = dateScheduled;    this.DatePerformed = datePerformed;
        this.PerformedBy = performedBy;        this.uri = uri;

   }

   public Assessment()
   {
        this.AssessmentId = Guid.NewGuid();    this.ApplicationId = string.Empty;
        this.AssessmentType = string.Empty;    this.RequestedBy = Guid.NewGuid();
        this.RequestedDate = DateTime.Now;     this.AssessmentOwner = Guid.NewGuid();
        this.ApplicationToTest = string.Empty; this.IsCompleted = false;
        this.DateScheduled = Convert.ToDateTime(DateScheduled);
        this.DatePerformed = Convert.ToDateTime(DatePerformed);
        this.PerformedBy = Guid.NewGuid();   this.uri = string.Empty;

   }
 public Guid AssessmentId  { get;     set;  }                
 public string ApplicationId   {get;  set;  }               
 public string AssessmentType  {get;  set;  }                
 public Guid RequestedBy  { get;    set;   }                
 public DateTime RequestedDate {get; set;  }
 public Guid AssessmentOwner  {get; set;  }
 public string ApplicationToTest {get; set;  }                
 public bool IsCompleted  { get;  set;  }
 public DateTime DateScheduled  {get; set;   }              
 public DateTime DatePerformed  { get;  set; }
 public Guid PerformedBy { get;  set;  }
 public string uri  { get; set; }
}


aspx.cs
  protected void bnSubmit_Click(object sender, EventArgs e)
   {
       Assessment asst = new Assessment(Guid.Parse(AssessmentId.Text),
           txtApplicationID.Text,
            DropDownList1.SelectedValue,
            requestedBy,
            DateTime.Now,
            Guid.Parse(txtAssessmentOwnerEmail.Text),
            ddlApplicationToTest.SelectedValue,
            false,
            CalendarExtender1.SelectedDate.GetValueOrDefault(),
            CalendarExtender2.SelectedDate.GetValueOrDefault(),
            Guid.Parse(txtPerfomedBy.Text),
            txtUri.Text);
    db.AddAssessment(asst);
  }

【问题讨论】:

  • 继续添加缺少的},看看会发生什么。
  • 抱歉,缺少 }。那一个在设置后关闭。我会发帖,因为它会很长
  • 代码没问题,所以尝试重启你的VS。
  • 如果没有其他人提到它,12 个参数就是一种代码味道。

标签: c# constructor compiler-errors


【解决方案1】:

要调查的事情:

  1. 在其他命名空间中是否还有其他名为Assessment 的类定义?
  2. 检查您的项目参考。确保您引用的程序集包含正确的 Assessment 定义。您可能在不知不觉中引用了该程序集的旧版本。
  3. 使用 ILSpy 等反汇编程序检查包含 Assessment 的程序集。验证它包含正确的类定义。

【讨论】:

  • 这很有用。谢谢!!
【解决方案2】:

发布的代码显示了Assessment 类的开始。该类没有关闭}

然后有一个函数调用(通常是页面类的一部分)创建一个新的评估类。

所以我猜这是你加入的两个文件来解释你的问题。这意味着您没有在页面类中包含 using - 或者名称中有拼写错误,或者在您的项目中引用了不同的文件。

Assessment 类也可能没有编译,但有一个先前编译的版本正在链接。

类似的东西。无论如何,这不是您使用的确切代码,因此我们不可能找出问题所在。你可以在某处放完整代码(bitbucket?),然后我们就可以看到问题所在了。

【讨论】:

  • 有一个结束 }。编辑代码。请检查。我也怀疑评估类是否使用了以前的编译版本。但我尝试重建几次。我没有找到干净的选项。
  • @user2340141 ...现在它有13个参数,这将与错误消息一致。
猜你喜欢
  • 2017-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-30
  • 1970-01-01
相关资源
最近更新 更多