Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Option Strict On does not allow narrowing in implicit type conversions between method '<methodname>' and delegate '<delegatename>'

Visual Studio 2008

With Option Strict on, you cannot have a narrowing conversion between the data type of a parameter in a delegate and the corresponding parameter of a function or Sub assigned to a variable of that delegate type. For example, function delegate Del has one parameter of type Integer, and functions Conversion1, Conversion2, and Conversion3 have one parameter of different numeric types.

Delegate Function Del(ByVal p As Integer) As String

Function Conversion1(ByVal n As Integer) As String
    Return "Valid"
End Function

Function Conversion2(ByVal n As Long) As String
    Return "Valid"
End Function

Function Conversion3(ByVal n As Short) As String
    Return "Not valid"
End Function

Because there is a widening conversion from Integer to Integer and to Long, the following assignments are valid.

' Valid.
Dim funDel1 As Del = AddressOf Conversion1
Dim funDel2 As Del = AddressOf Conversion2

The conversion from Integer to Short is a narrowing conversion. Therefore, the following assignment is not valid.

' Not valid.
Dim funDel3 As Del = AddressOf Conversion3

Error ID: BC36663

To correct this error

  • Change the data type of the parameter in the delegate or the method so that the required widening relationship exists.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.