[英]Overload resolution failed because no accessible 'New' is most specific for these arguments:
I have a usercontrol with a repeater.我有一个带中继器的用户控件。 Originally in page load I had code which grabbed data from the database and bound to the repeater.最初在页面加载时,我有从数据库中获取数据并绑定到转发器的代码。 I now want to take this functionality outside of the usercontrol so that I can have more than one on the page and have them bind to different data.我现在想把这个功能放在用户控件之外,这样我就可以在页面上有多个,并将它们绑定到不同的数据。
My code now is:我现在的代码是:
Imports System.ComponentModel
Public Class UpdateList
Inherits System.Web.UI.UserControl
Private m_dataSource As Object
<TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")> _
<Category("Data")> _
<DefaultValue(Nothing)> _
Public Property DataSource() As Object
Get
Return Me.m_dataSource
End Get
Set(value As Object)
If Me.m_dataSource <> value Then
m_dataSource = value
tryDataBinding()
End If
End Set
End Property
Public ReadOnly Property UpdateCount As Integer
Get
Return m_UpdateCount
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub tryDataBinding()
rep_Updates.DataSource = Me.m_dataSource
rep_Updates.DataBind()
End Sub
End Class
I get a wavy line at <DefaultValue(Nothing)>
and get an error:我在<DefaultValue(Nothing)>
处得到一条波浪线并得到一个错误:
Overload resolution failed because no accessible 'New' is most specific for these arguments:重载解析失败,因为没有可访问的“新”是这些参数最具体的:
'Public Sub New(value As Boolean)': Not most specific. 'Public Sub New(value As Boolean)':不是最具体的。
'Public Sub New(value As Byte)': Not most specific. 'Public Sub New(value As Byte)':不是最具体的。
'Public Sub New(value As Char)': Not most specific. 'Public Sub New(value As Char)':不是最具体的。
What does this mean?这是什么意思? Thanks谢谢
UPDATE更新
The fix was to change the property declaration for datasource to...解决方法是将数据源的属性声明更改为...
Private m_dataSource As Object
Public Property DataSource() As Object
Get
Return Me.m_dataSource
End Get
Set(value As Object)
m_dataSource = value
tryDataBinding()
End Set
End Property
at least in WinForms the DefaultValue attribute ctor cant be Nothing
(there is no such definition in Object Browser). 至少在WinForms中 ,DefaultValue属性ctor不能为Nothing
(在对象浏览器中没有这样的定义)。 DefaultAttribute
doesnt define an initial starting value (in spite of the name), but the comparison value for when to persist a property value. DefaultAttribute
并未定义初始起始值(尽管有名称),但是定义了何时保留属性值的比较值。 This seems dubious anyway in the case of a webform and datasource, so just remove the attribute. 无论如何,对于Web表单和数据源来说,这似乎都是可疑的,因此只需删除该属性即可。
As you noted the TypeConverter
is probably out of place as well. 如您所述, TypeConverter
可能也TypeConverter
。
I get a wavy line at
<DefaultValue(Nothing)>
and […] an error: 我在<DefaultValue(Nothing)>
处出现波浪线,并[…]出现错误:Overload resolution failed because no accessible 'New' is most specific for these arguments: 重载解析失败,因为对于这些参数,没有可访问的“新建”是最具体的:
Public Sub New(value As Boolean)
: Not most specific.Public Sub New(value As Boolean)
:不是最具体的。
Public Sub New(value As Byte)
: Not most specific.Public Sub New(value As Byte)
:并非最具体。
Public Sub New(value As Char)
: Not most specific.Public Sub New(value As Char)
:不是最具体。
DefaultValueAttribute
constructor is overloaded. DefaultValueAttribute
构造函数已重载。 This error means that the VB.NET compiler has trouble deciding which of the overloads to invoke for <DefaultValue(Nothing)>
. 此错误意味着VB.NET编译器难以确定要为<DefaultValue(Nothing)>
调用哪些重载。 The problem is that Nothing
in VB.NET can actually mean two things: 问题在于,VB.NET中的Nothing
实际上都不能表示两件事:
null
in C#) 空引用(在C#中为null
) default(T)
in C#) 为其分配类型的默认值default(T)
C#中的default(T)
) Because of that, every single one of the available constructor overloads could be chosen. 因此,可以选择可用的构造函数重载中的每个重载。 You obviously intend VB.NET to choose the Public Sub New(value As Object)
overload , but the compiler simply isn't smart enough to recognise this. 您显然打算让VB.NET选择Public Sub New(value As Object)
重载 ,但是编译器根本不够聪明,无法识别这一点。
Unfortunately, it doesn't seem to be possible to make Nothing
more specific, eg via CObj(Nothing)
, because only constant values are allowed as custom attribute arguments. 不幸的是,使Nothing
变得更具体似乎是不可能的,例如通过CObj(Nothing)
,因为只允许使用常量值作为自定义属性参数。
If I find a solution to this VB.NET-specific problem, I'll update my answer. 如果找到此VB.NET特定问题的解决方案,则将更新答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.