Data type(s) of the type parameter(s) in method '<methodname>' cannot be inferred from these arguments because they do not convert to the same type
Data type(s) of the type parameter(s) in method '<methodname>' cannot be inferred from these arguments because they do not convert to the same type. 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 procedure. The compiler could not find a data type that meets the constraints of all the arguments. Therefore, it reported this 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.
Option Strict Off
Module Module1
Sub Main()
'' Not valid. Integer and Date do not convert to the same type.
'targetMethod(19, #3/4/2007#)
End Sub
Sub targetMethod(Of T)(ByVal p1 As T, ByVal p2 As T)
End Sub
End Module
Error ID: BC36660 and BC36657
To correct this error
You may be able to convert one or more arguments explicitly to a compatible type, as shown in the following code:
targetMethod(19, #3/4/2007#.ToOADate)
You may be able to specify a data type for the type parameter or parameters to which the arguments convert, as shown in the following code:
targetMethod(Of String)(19, #3/4/2007#)
See Also
Concepts
Generic Procedures in Visual Basic
Implicit and Explicit Conversions