Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a repro of this behavior. It also shows you the workaround, cast with CObj():</p> <pre><code>Module Module1 Sub Main() Dim itf As IFoo = New CFoo() Console.WriteLine(itf.ToString()) '' Error BC30455 Console.WriteLine(CObj(itf).ToString()) '' Okay End Sub End Module Interface IFoo Function ToString(ByVal mumble As Integer) As String End Interface Class CFoo Implements IFoo Function ToString1(ByVal mumble As Integer) As String Implements IFoo.ToString Return "foo" End Function End Class </code></pre> <p>I think this is annotated in the VB.NET Language Specification, chapter 11.8.1 "Overloaded method resolution":</p> <blockquote> <p>The justification for this rule is that if a program is loosely-typed (that is, most or all variables are declared as Object), overload resolution can be difficult because all conversions from Object are narrowing. Rather than have the overload resolution fail in many situations (requiring strong typing of the arguments to the method call), resolution the appropriate overloaded method to call is deferred until run time. This allows the loosely-typed call to succeed without additional casts.</p> <p>An unfortunate side-effect of this, however, is that performing the late-bound call requires casting the call target to Object. In the case of a structure value, this means that the value must be boxed to a temporary. If the method eventually called tries to change a field of the structure, this change will be lost once the method returns.</p> <p>Interfaces are excluded from this special rule because late binding always resolves against the members of the runtime class or structure type, which may have different names than the members of the interfaces they implement.</p> </blockquote> <p>Not sure. I'd transliterate it as: VB.NET is a loosely typed language where many object references are commonly late bound. This makes method overload resolution perilous.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload