简体   繁体   English

VB.NET中的问题覆盖方法(错误BC30284)

[英]Problem overriding methods in VB.NET (Error BC30284)

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. MyType是来自外部COM库的类型。 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. 我已经向包含基类和派生类的项目添加了必需的COM引用。 Any idea how to get rid of this error? 任何想法如何摆脱这个错误? I'm using VS2005 and .NET 2.0 我正在使用VS2005和.NET 2.0

Edit: Every other override is working fine, I'm only getting error if I'm using referenced COM types as parameters. 编辑:所有其他替代都工作正常,如果我将引用的COM类型用作参数,只会收到错误消息。 If I change Parameter to Object, overriding works fine. 如果我将“参数”更改为“对象”,则重写可以正常工作。

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.exe从COM类型库生成静态DLL,并从两个项目中进行引用(而不是使用COM引用)以确保它们引用的是完全相同的东西? 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). TlbImp包含在Visual Studio中,但是在仅安装Visual Studio Express的系统上找不到它,因此,如果您使用Express,则可能必须寻找它(链接的页面可能有也可能没有您想要的版本)。 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. 我怀疑如果每个项目都有自己的COM引用,则Visual Studio可能会为每个项目创建一个单独的COM包装器,并且在生成GUID和其他方面时,生成的COM包装器可能不会完全彼此一致。 So by creating a and forcing the use of a single wrapper you may be able to eliminate that as a possible problem. 因此,通过创建一个并强制使用单个包装器,您可以消除这种可能的问题。

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. 如果您有不同的参数或数据类型,请检查基类和派生类中Function的签名,否则任何参数都不匹配。 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 V

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. 除了使用TlbImp之外,另一个选择是拥有一个单独的项目,在该项目中,您将MyType封装在.NET类中,并将该项目包括在两个示例中。

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. 因此,您最终将获得一个中间的MyDotNetType,它将作为构造函数参数Mytype(COM对象)并将其公开为只读属性。 Then the MySub call, would take the MyDotNetType as an argument. 然后,MySub调用将MyDotNetType作为参数。

Kind Regards 亲切的问候

Noel 诺埃尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM