Method binding to base method in external library can't handle new virtual methods "between"
<p>Lets say I have a library, version 1.0.0, with the following contents:</p>

<pre><code>public class Class1
{
    public virtual void Test()
    {
        Console.WriteLine( "Library:Class1 - Test" );
        Console.WriteLine( "" );
    }
}
public class Class2 : Class1
{
}
</code></pre>

<p>and I reference this library in a console application with the following contents:</p>

<pre><code>class Program
{
    static void Main( string[] args )
    {
        var c3 = new Class3();
        c3.Test();
        Console.ReadKey();
    }
}
public class Class3 : ClassLibrary1.Class2
{
    public override void Test()
    {
        Console.WriteLine("Console:Class3 - Test");
        base.Test();
    }
}
</code></pre>

<p>Running the program will output the following:</p>

<pre><code>Console:Class3 - Test
Library:Class1 - Test
</code></pre>

<p>If I build a new version of the library, version 2.0.0, looking like this:</p>

<pre><code>public class Class1
{
    public virtual void Test()
    {
        Console.WriteLine( "Library:Class1 - Test V2" );
        Console.WriteLine( "" );
    }
}

public class Class2 : Class1
{
    public override void Test()
    {
        Console.WriteLine("Library:Class2 - Test V2");
        base.Test();
    }
}
</code></pre>

<p>and copy this version to the bin folder containing my console program and run it, the results are:</p>

<pre><code>Console:Class3 - Test
Library:Class1 - Test V2
</code></pre>

<p>I.e, the Class2.Test method is never executed, the base.Test call in Class3.Test seems to be bound to Class1.Test since Class2.Test didn't exist when the console program was compiled.
This was very surprising to me and could be a big problem in situations where you deploy new versions of a library without recompiling applications. </p>

<p>Does anyone else have experience with this? </p>

<p>Are there any good solutions?</p>

<p>This makes it tempting to add empty overrides that just calls base in case I need to add some code at that level in the future...</p>

<p>Edit:</p>

<p>It seems to be established that the call is bound to the first existing base method at compile time. I wonder why. If I build my console program with a reference to version 2 of my library (which should mean that the call is compiled to invoke Class2.Test ) and then replace the dll in the bin folder with version 1 the result is, as expected:</p>

<pre><code>Console:Class3 - Test
Library:Class1 - Test
</code></pre>

<p>So there is no runtime error when Class2.Test doesn't exist. Why couldn't the base call have been compiled to invoke Class2.Test in the first place?</p>

<p>It would be interesting to get a comment from Eric Lippert or someone else who works with the compiler...</p>
