临时文件包含对不带参数的构造函数的引用,而本不应该这样做
我有一些 WebUserControls,它们采用一个参数来确定它们如何初始化自身。但是,当我编译页面时,出现错误“
'ControlName' does not contain a constructor that takes '0' arguments
I am not call it everything without a argument”,似乎正在临时文件中生成引用。我有另一个控件,它没有空的构造函数,并且不需要在那里创建一个,因此它不必有一个。
实际的错误看起来像这样:
编译器错误消息:CS1729:
“ControlName”不包含 采用“0”参数的构造函数
来源错误:
第 108 行:私有静态布尔值 @__初始化; 109号线: 110:
[系统.诊断.DebuggerNonUserCodeAttribute()] 第 111 行:公共 control_ascx() { 第 112 行:
((global::ControlNamespace)(this)).AppRelativeVirtualPath =“~/ControlName.ascx”;源文件: (路径)Local\Temp\临时 ASP.NET 文件\root\1aca8e08\3fab105e\App_Web_controlname.ascx.cdcab7d2.tzm0xzkd.0.cs 线路:110
该控件看起来像这样:
public partial class ControlName: System.Web.UI.UserControl
{
public ControlName(IParameter parameter)
{
Method(parameter);
}
}
编辑:根据下面的注释,我似乎在设计器文件中引用了该控件...某处...我能找到的所有引用都位于代码后面有一个例外。 .ascx 文件中的声明:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ControlName.ascx.cs" Inherits="Control" %>
我认为这是罪魁祸首,但经过进一步检查,我有其他具有类似声明且不需要默认构造函数的控件。
如何找到引用控件的位置?
解决方案:
我有参考标签
<%@ Reference Control="~/ControlName.ascx" %>
早期留下的内容显然算作设计器元素。
下面的答案实际上并不包含此信息,而是一个很好地描述了问题所在。
I have some WebUserControls that take a parameter to determine how they initialize themselves. However, when I compile the page I get the error
'ControlName' does not contain a constructor that takes '0' arguments
I am not calling it anywhere without an argument, it appears that a reference is being generated in a temporary file. I have another control that doesn't have a empty constructor and it is not requiring one to be created there so it shouldn't have to have one.
The actual error looks like this:
Compiler Error Message: CS1729:
'ControlName' does not contain a
constructor that takes '0' argumentsSource Error:
Line 108: private static bool
@__initialized; Line 109: Line
110:
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 111: public control_ascx()
{ Line 112:
((global::ControlNamespace)(this)).AppRelativeVirtualPath
= "~/ControlName.ascx";Source File:
(Path)Local\Temp\Temporary ASP.NET
Files\root\1aca8e08\3fab105e\App_Web_controlname.ascx.cdcab7d2.tzm0xzkd.0.cs
Line: 110
The control looks like this:
public partial class ControlName: System.Web.UI.UserControl
{
public ControlName(IParameter parameter)
{
Method(parameter);
}
}
EDIT: Based on the comments below it would appear that I have a reference to the control in a designer file...somewhere... All references that I can find are located in code behinds with one exception. The declaration in the .ascx file:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ControlName.ascx.cs" Inherits="Control" %>
I thought that this was the culprit but upon further inspection I have other controls which have a similar declaration and do NOT require a default constructor.
How can I find the location where the control is referenced from?
Solution:
I had reference tags
<%@ Reference Control="~/ControlName.ascx" %>
leftover from earlier that apparently count as a designer element.
The answer below does not actually contain this information but is a good description of what the problem was.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不是 Web 开发方面的专家,但看起来您已经在 Web 表单设计器上放置了一个控件实例,并且该设计器正在生成需要无参数构造函数的代码。
如果是这种情况,那么要解决此问题,您应该从表单中删除该控件或添加无参数构造函数。
I'm no expert on web development, but it looks like you've got an instance of the control placed on a web form designer, and that designer is generating code that expects a parameterless constructor.
If this is the case, then to solve this problem, you should either remove the control from the form or add a parameterless constructor.
CLR 试图调用您的类的超类的默认构造函数,但它不能。对合适的基本构造函数进行显式调用。
The CLR is trying to call the default constructor of the super class to your class, but it cannot. Put an explicit call to a suitable base constructor.
当您有不带参数的 ctor 时,它会尝试不带参数调用父类的 ctor 。但它的基类没有。
when you have ctor without parameters it tries to call parent's class ctor without parameters. but it's base class doesn't have one.
我不知道你是否属于这种情况。我过去在处理对象序列化时遇到过编译错误。如果我没记错的话,当我们专门使用 XML 序列化时,我们会收到此错误。反序列化对象时,运行时使用默认构造函数,因此如果没有默认构造函数,则会被编译器标记。
I do not know if this is the case for you. I have in the past gotten that compile error when working with object serialization. If I remember correctly, when we were using XML serialization exclusively, we would get this error. When deserializing the object, the runtime was using the default constructor, so if it did not have one, it was flagged by the compiler.
根据您的编辑,我认为这实际上可能是因为您选择的名称...
Control
。有很多Control
类,ascx 中的声明可能存在命名空间冲突问题。尝试将您的控件重命名为其他名称。Based on your edit, I think this may actually be because of the name you chose...
Control
. There are lots ofControl
classes, and it could be that the declare in the ascx is having issues with a namespace conflict. Try renaming your Control to something else.