Udostępnij za pośrednictwem


Data type(s) of the type parameter(s) in extension method '<methodname>' defined in '<typename>' cannot be inferred from these arguments

Data type(s) of the type parameter(s) in extension method '<methodname>' defined in '<typename>' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.

An attempt has been made to use type inference to determine the data type (or types) of the type parameter (or parameters) when evaluating a call to a generic extension method. However, the compiler is not able to find a data type for the type parameters in this method, and it reports the error.

Note

When specifying arguments is not an option (for example, for query operators in query expressions), the error message appears without the second sentence.

The following code demonstrates the error.

Module Module1

    Sub Main()

        Dim classInstance As ClassExample

        '' Not valid.
        'classInstance.GenericExtensionMethod("Hello", "World")

    End Sub

    <System.Runtime.CompilerServices.Extension()> _
    Sub GenericExtensionMethod(Of T)(ByVal classEx As ClassExample, _
                                     ByVal x As String, ByVal y As _
                                     InterfaceExample(Of T))
    End Sub

End Module

Interface InterfaceExample(Of T)
End Interface

Class ClassExample
End Class

Error ID: BC36649 and BC36646

To correct this error

  • You may be able to specify a data type for the type parameter or parameters instead of relying on type inference.

See Also

Concepts

Relaxed Delegate Conversion

Extension Methods (Visual Basic)

Generic Procedures in Visual Basic

Other Resources

Type Conversions in Visual Basic