Type argument inference failed for type parameter '<typeparametername1>' of '<genericproceduresignature>'

Type argument inference failed for type parameter '<typeparametername1>' of '<genericproceduresignature>'. Type argument inferred from the argument passed to parameter '<parametername1>' conflicts with the type argument inferred from the argument passed to parameter '<parametername2>'.

A generic procedure is called without any type arguments, and the attempted type inference has produced a data type conflict among the type parameters.

Normally, when you call a generic procedure, you supply a type argument for each type parameter that the generic procedure defines. If you do not supply any type arguments, then the compiler attempts to infer the types to be passed to the type parameters. If the context of the call provides conflicting data type information for a type parameter, then the type inference fails.

The following code can generate this error.

Public Sub takeTwoValues(Of t)(ByVal x As t, ByVal y As t)
End Sub
Call takeTwoValues(4, 2.5)

Because the first argument causes the compiler to infer Integer for type parameter t, while the second argument causes it to infer Double for the same type parameter, there is a conflict regarding which data type to pass to t.

Error ID: BC32116

To correct this error

  • Supply type arguments to the generic type, so that the compiler does not have to infer them.

    Call takeTwoValues(Of Double)(4, 2.5)
    

    Notice that in this case, where the two normal arguments are of different data types, the calling code must pass a type argument that can accommodate both of those data types. In this case, Integer widens to Double.

    -or-

  • Redefine the generic procedure to specify different type parameters for the normal parameters, so that there is no conflict inferring the types.

    Public Sub takeTwoValues(Of t1, t2)(ByVal x As t1, ByVal y As t2)
    

See Also

Concepts

Generic Types in Visual Basic

Generic Procedures in Visual Basic

Reference

Type List