Property '<propertyname>' cannot be initialized in an object initializer expression because all accessible overloads require arguments

The members initialized in an object initializer list must be either fields or properties. Additionally, properties in an initializer list cannot have parameters. The property causing this error is overloaded, and each of its versions requires arguments. Therefore, the property cannot be initialized in an object initializer list.

Error ID: BC30993

To correct this error

  • Remove the property that requires arguments from the initializer list.

Example

The following class contains three property definitions: one for TotalItems and two for Item, which is overloaded.

    Class CollectionOfItems
        Property TotalItems() As Integer
            Get
            End Get
            Set(ByVal value As Integer)
            End Set
        End Property
        Property Item(ByVal Key As String) As Object
            Get
            End Get
            Set(ByVal value As Object)
            End Set
        End Property
        Property Item(ByVal Index As Integer) As Object
            Get
            End Get
            Set(ByVal value As Object)
            End Set
        End Property
    End Class

The TotalItems property requires no arguments and can be initialized in an object initialization list, as shown in the following declaration.

Dim coinCollection As New CollectionOfItems With { .TotalItems = 0 }

The Item property is overloaded, and each overload requires an argument. Therefore, Item cannot appear in an object initializer list.

' The following declaration is not valid.
' Dim coinCollection As New CollectionOfItems With { .TotalItems = 0, _
'    .Item = aCoinObject }

To avoid this error, initialize the Item property outside the object initializer.

Dim coinCollection As New CollectionOfItems With { .TotalItems = 0 }
coinCollection.Item(1) = aCoinObject

See Also

Tasks

How to: Call a Property Procedure

Concepts

Properties and Property Procedures

Object Initializers: Named and Anonymous Types

Default Properties

Procedure Overloading

Reference

Overloads