Reputation: 3480
I'm in the process of converting a legacy VB.NET application into a C# application. The VB.NET application references an external .DLL (ExternalLib.dll) that has the class MyClass
which implements IMyClass
.
In VB.NET, this code compiles and executes without problems:
Dim external As New MyClass
external.DoMethod(1)
In C#, this code throws a compile-time error:
MyClass external = new MyClass();
external.DoMethod(1);
'ExternalLib.MyClass' does not contain a definition for 'DoMethod' and no extension method 'DoMethod' accepting a first argument of type 'ExternalLib.MyClass' could be found (are you missing a using directive or an assembly reference?)
Looking at the metadata, IMyClass
doesn't have DoMethod()
. In VB.NET's Intellisense, DoMethod()
does not show up among the other available public methods, but everything compiles and runs just fine.
Upvotes: 1
Views: 369
Reputation: 3480
The VB.NET application is using late-binding with option strict off
to access the hidden method in ExternalLib.dll. Using the dynamic
keyword allows for the same behavior in the C# application:
dynamic external = new MyClass();
external.DoMethod(1);
(Kudos to Blorgbeard for pointing me in the right direction.)
Upvotes: 0
Reputation: 6795
Is DoMethod()
a static method or an instance method? If it was a static method that would explain why you can't see it in the interface. You need to change your C# code to this:
MyClass.DoMethod(1);
Upvotes: 1