views:

566

answers:

3

I have an overridable sub in my base class

Project1:
Public Class BaseClass
    Protected Overridable Sub MySub(ByVal Parameter as MyType)
End Class

Project2:
Public Class DerivedClass
    Inherits BaseClass
    Protected Overrides Sub MySub(ByVal Parameter as MyType)
End Class

MyType is a type that comes from external COM library. When I'm trying to override it in a derived class, I'm getting

error BC30284: sub 'MySub' cannot be declared 'Overrides' because it does not override a function in a base class

I've added the required COM reference to both projects containing base and derived classes. Any idea how to get rid of this error? I'm using VS2005 and .NET 2.0

Edit: Every other override is working fine, I'm only getting error if I'm using referenced COM types as parameters. If I change Parameter to Object, overriding works fine.

+2  A: 

Have you considered or tried using TlbImp.exe to generate a static DLL from the COM type library, and reference that from both projects (instead of using a COM reference) to make sure they are referring to exactly the same thing? TlbImp is included with Visual Studio, but I can't find it on my system with only Visual Studio Express installed, so if you're using express, you might have to go hunting for it (the linked page may or may not have the version you want). I suspect that if each project has their own COM reference, Visual Studio may be creating a separate COM wrapper for each project and the generated COM wrappers may not entirely agree with each other when it comes to generated GUIDs and whatnot. So by creating a and forcing the use of a single wrapper you may be able to eliminate that as a possible problem.

BlueMonkMN
+1  A: 

Rather than using TlbImp, another option is to have a separate project where you encapsulate the MyType in a .NET class and include that project in both your samples.

So you would end up with an intermediate MyDotNetType which would take as a constructor argument Mytype (the COM object) and expose it out as a read-only property. Then the MySub call, would take the MyDotNetType as an argument.

Kind Regards

Noel

Bigtoe
+1  A: 

Please check the signature of the Function in both base class and derived class, if you have different agruments or data type o any arguments is not matched. Then you'll get this type of error. Simple please check the function name, argument name and data type. It worked me. I hope this answer will be helpful.

Thanks, Ramu V

Ramu