Method Overriding Issues in VB.NET (Bug BC30284)
I have an overridden 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 an external COM library. When I try to override it in a derived class I get
error BC30284: sub 'MySub' cannot be declared 'Overrides' because it does not override a function in a base class
I have added the required COM reference for both projects containing base and derived classes. Any idea how to get rid of this error? I am using VS2005 and .NET 2.0
Edit: Any other override works fine, I only get the error if I use referenced COM types as parameters. If I change the parameter to an object, the override works fine.
a source to share
Have reviewed or tried to use TlbImp.exeto create a static DLL from a COM type library and reference both projects (instead of using a COM reference) to make sure they refer to exactly the same thing? TlbImp is included in Visual Studio, but I can't find it on my system with just Visual Studio Express installed, so if you are using express you might have to go looking (the linked page may or may not have the version you want ). I suspect that if each project has its own COM code, Visual Studio might create a separate COM wrapper for each project, and the generated COM wrappers might not exactly match each other when it comes to generated GUIDs and whatnot. Thus, by creating and forcing one shell to use, you can eliminate it as a possible problem.
a source to share
Instead of using TlbImp, another option is to have a separate project where you encapsulate MyType in a .NET class and include that project in both samples.
So, you will have an intermediate MyDotNetType that will take Mytype (COM object) as a constructor argument and expose it as a read-only property. Then the call to MySub will take MyDotNetType as an argument.
Yours faithfully
Noel
a source to share
Please check the function signature in both the base class and the derived class if you have different arguments or data types. o any arguments are not matched. Then you get this type of error. Simple, please check the function name, argument name and data type. It worked. I hope this answer is helpful.
Thank you, Ramu V
a source to share