I have a C# library that has an extension method, something like:
public interface ISomething { ... }
public class SomethingA : ISomething { ... }
public class SomethingB : ISomething { ... }
public static class SomethingExtensions
{
public static int ExtensionMethod(this ISomething input, string extra)
{
}
}
The extension works fine if called from C#, but has an issue if called from an external VB.Net application:
Dim something = Me.SomethingManager.GetSomething(key)
Dim result = something.ExtensionMethod("extra")
This compiles fine but throws an exception at run time:
Public member 'ExtensionMethod' on type 'SomethingB' not found.
If the VB.Net is changed to explicitly make the type the interface it works:
Dim something as ISomething = Me.SomethingManager.GetSomething(key)
Dim result = something.ExtensionMethod("extra")
Why? Why does the extension method work on the interface but not the class that implements it? Would I have the same issue if I used a subclass? Is VB.Net's implementation of extension methods incomplete?
Is there anything I can do in the C# library to make VB.Net work without the explicit interface?