后期绑定重载决策不能应用于“<procedurename>”,因为访问实例是一个接口类型Latebound overload resolution cannot be applied to '<procedurename>' because the accessing instance is an interface type

编译器尝试解析对重载属性或过程的引用,但引用失败,因为参数的类型为 Object ,而引用对象具有接口的数据类型。The compiler is attempting to resolve a reference to an overloaded property or procedure, but the reference fails because an argument is of type Object and the referring object has the data type of an interface. Object参数强制编译器将引用解析为晚期绑定。The Object argument forces the compiler to resolve the reference as late-bound.

在这些情况下,编译器通过实现类解析重载,而不是通过基础接口解析。In these circumstances, the compiler resolves the overload through the implementing class instead of through the underlying interface. 如果类重命名其中一个重载版本,则编译器不会将该版本视为重载,因为其名称不同。If the class renames one of the overloaded versions, the compiler does not consider that version to be an overload because its name is different. 这进而导致编译器忽略重命名的版本,因为它可能是解析引用的正确选择。This in turn causes the compiler to ignore the renamed version when it might have been the correct choice to resolve the reference.

错误 ID: BC30933Error ID: BC30933

更正此错误To correct this error

  • 使用 CType 将参数从强制转换 Object 为你要调用的重载的签名所指定的类型。Use CType to cast the argument from Object to the type specified by the signature of the overload you want to call.

    请注意,它不会帮助将引用对象强制转换为基础接口。Note that it does not help to cast the referring object to the underlying interface. 必须强制转换参数以避免此错误。You must cast the argument to avoid this error.

示例Example

下面的示例演示对重载 Sub 过程的调用,该过程在编译时导致此错误。The following example shows a call to an overloaded Sub procedure that causes this error at compile time.

Module m1
    Interface i1
        Sub s1(ByVal p1 As Integer)
        Sub s1(ByVal p1 As Double)
    End Interface
    Class c1
        Implements i1
        Public Overloads Sub s1(ByVal p1 As Integer) Implements i1.s1
        End Sub
        Public Overloads Sub s2(ByVal p1 As Double) Implements i1.s1
        End Sub
    End Class
    Sub Main()
        Dim refer As i1 = New c1
        Dim o1 As Object = 3.1415
        ' The following reference is INVALID and causes a compiler error.
        refer.s1(o1)
    End Sub
End Module

在前面的示例中,如果编译器允许调用编写的 s1 ,则通过类 c1 而不是接口进行解析 i1In the preceding example, if the compiler allowed the call to s1 as written, the resolution would take place through the class c1 instead of the interface i1. 这意味着编译器不会考虑 s2 ,因为它的名称在中是不同的 c1 ,即使它是定义的正确选择 i1This would mean that the compiler would not consider s2 because its name is different in c1, even though it is the correct choice as defined by i1.

可以通过将调用更改为以下代码行之一来更正此错误:You can correct the error by changing the call to either of the following lines of code:

refer.s1(CType(o1, Integer))
refer.s1(CType(o1, Double))

前面的每个代码行显式将变量强制 Object 转换 o1 为为重载定义的参数类型之一。Each of the preceding lines of code explicitly casts the Object variable o1 to one of the parameter types defined for the overloads.

另请参阅See also