Data type(s) of the type parameter(s) in extension method '<methodname>' defined in 'typename' cannot be inferred from these arguments because they do not convert to the same type
Data type(s) of the type parameter(s) in extension method '<methodname>' defined in 'typename' 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 extension method. 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 Module3
Sub Main()
Dim c1 As New Class1
'' Not valid. Integer and Date do not convert to the same type.
'c1.targetMethod(19, #3/4/2007#)
End Sub
<System.Runtime.CompilerServices.Extension()> _
Sub targetMethod(Of T)(ByVal p0 As Class1, ByVal p1 As T, ByVal p2 As T)
End Sub
Class Class1
End Class
End Module
Error ID: BC36661 and BC36658
To correct this error
You might be able to convert one or more arguments explicitly to a compatible type, as shown in the following code:
c1.targetMethod(19, #3/4/2007#.ToOADate)
You might be able to specify a data type for the type parameter or parameters to which the arguments convert, as shown in the following code:
c1.targetMethod(Of String)(19, #3/4/2007#)
See Also
Concepts
Extension Methods (Visual Basic)
Generic Procedures in Visual Basic
Implicit and Explicit Conversions