The overload error failed because New was not available for these arguments.

I have a usercontrol with a repeater. Initially, in the page load, I had code that grabbed data from a database and attached to a relay. Now I want to use this functionality outside of user control, so that I have more than one on the page and bind to different data.

Now my code 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 in <DefaultValue(Nothing)> and get an error message:

An overload error is not possible because the "New" is not the most accessible for these arguments:

'Public Sub New (meaning As Boolean)': not the most specific.

'Public Sub New (value as byte)': not the most specific.

'Public Sub New (meaning As Char)': Not the most accurate.

What does it mean? Thanks

UPDATE

The fix is ​​to change the property declaration for the data source 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 
+1
source share
2 answers

at least in WinForms, the DefaultValue ctor can not Nothing attribute (there is no such definition in the Object Browser). DefaultAttribute does not define the initial starting value (despite the name), but the comparison value for when you want to save the value of the property. In any case, this seems doubtful in the case of a web form and data source, so just remove the attribute.

As you noticed, TypeConverter is probably also inappropriate.

0
source

I get a wavy line in <DefaultValue(Nothing)> and [...] an error:

An overload error is not possible because the "New" is not the most accessible for these arguments:

Public Sub New(value As Boolean) : Not the most specific.
Public Sub New(value As Byte) : Not the most specific.
Public Sub New(value As Char) : not the most specific.

Constructor

DefaultValueAttribute overloaded. This error means that the VB.NET compiler cannot decide which of the overloads to cause for <DefaultValue(Nothing)> . The problem is that Nothing in VB.NET can mean two things:

  • null reference ( null in C #)
  • default value for the type to which it is assigned ( default(T) in C #)

Because of this, you can select each of the available constructor overloads. You obviously intend VB.NET to choose Public Sub New(value As Object) overload , but the compiler is simply not smart enough to recognize this.

Unfortunately, it seems impossible to make Nothing more specific, for example. via CObj(Nothing) , since only constant values ​​are allowed as arguments to custom attributes.

If I find a solution to this VB.NET-specific problem, I will update my answer.

0
source

All Articles