![](/img/trans.png)
[英]Overload resolution failed because no accessible 'new' is most specific for these arguments
[英]Overload resolution failed because no accessible 'New' is most specific for these arguments:
我有一个带中继器的用户控件。 最初在页面加载时,我有从数据库中获取数据并绑定到转发器的代码。 我现在想把这个功能放在用户控件之外,这样我就可以在页面上有多个,并将它们绑定到不同的数据。
我现在的代码是:
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
我在<DefaultValue(Nothing)>
处得到一条波浪线并得到一个错误:
重载解析失败,因为没有可访问的“新”是这些参数最具体的:
'Public Sub New(value As Boolean)':不是最具体的。
'Public Sub New(value As Byte)':不是最具体的。
'Public Sub New(value As Char)':不是最具体的。
这是什么意思? 谢谢
更新
解决方法是将数据源的属性声明更改为...
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
至少在WinForms中 ,DefaultValue属性ctor不能为Nothing
(在对象浏览器中没有这样的定义)。 DefaultAttribute
并未定义初始起始值(尽管有名称),但是定义了何时保留属性值的比较值。 无论如何,对于Web表单和数据源来说,这似乎都是可疑的,因此只需删除该属性即可。
如您所述, TypeConverter
可能也TypeConverter
。
我在
<DefaultValue(Nothing)>
处出现波浪线,并[…]出现错误:重载解析失败,因为对于这些参数,没有可访问的“新建”是最具体的:
Public Sub New(value As Boolean)
:不是最具体的。
Public Sub New(value As Byte)
:并非最具体。
Public Sub New(value As Char)
:不是最具体。
DefaultValueAttribute
构造函数已重载。 此错误意味着VB.NET编译器难以确定要为<DefaultValue(Nothing)>
调用哪些重载。 问题在于,VB.NET中的Nothing
实际上都不能表示两件事:
null
) default(T)
C#中的default(T)
) 因此,可以选择可用的构造函数重载中的每个重载。 您显然打算让VB.NET选择Public Sub New(value As Object)
重载 ,但是编译器根本不够聪明,无法识别这一点。
不幸的是,使Nothing
变得更具体似乎是不可能的,例如通过CObj(Nothing)
,因为只允许使用常量值作为自定义属性参数。
如果找到此VB.NET特定问题的解决方案,则将更新答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.