我有WSDL生成的类
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class FVZServicesClient : System.ServiceModel.ClientBase<FVZScanningDocumentInfo.FVZServices.FVZServices>, FVZScanningDocumentInfo.FVZServices.FVZServices {
...
}
我需要提供VB6中使用的库。我使用碰巧使用上述类的COM接口。
当我用
注册程序集时regasm MyAssembly.dll /tlb:MyAssembly.tlb
我收到错误消息
Microsoft .NET Framework程序集注册实用程序版本 适用于Microsoft .NET Framework版本4.7.3062.0的4.7.3062.0版权所有(C)Microsoft Corporation。保留所有权利。
类型成功注册类型库导出器警告处理 “ MyAssembly.FVZServices.FVZServicesClient,MyAssembly”。警告:类型 库导出程序遇到了从通用类派生的类型 并且未标记为[ClassInterface(ClassInterfaceType.None)]。类 此类类型的接口不能公开。考虑标记类型 与[ClassInterface(ClassInterfaceType.None)]并暴露一个 显式接口作为使用COM的COM的默认接口 ComDefaultInterface属性。组装出口到 'C:\ Users \ MyName \ Documents \ ScanLibrary \ Packet \ MyAssembly.tlb',然后 类型库已成功注册
当我按照建议将属性[ClassInterface(ClassInterfaceType.None)]
添加到FVZServicesClient时,下次尝试加气时仍会收到相同的错误消息。我知道生成的代码可以随时覆盖,但是我通过DotPeek验证了ClassInterface属性仍在编译后的代码中。
我尝试的另一件事是创建FVZServicesClient的具有ClassInterface属性的部分类。消息提示,我还用COMDefaultInterface标记了默认接口。结果是一样的。为FVZServicesClient添加属性[ComVisible(false)]
也无济于事。
在VB6中引用该库时,编译会导致错误:“未定义用户定义类型”。
如何从COM接口中排除FVZServicesClient?
答案 0 :(得分:0)
尝试将属性[ComVisible(false)]
添加到class FVZServicesClient
。
我不确定您的代码生成过程如何工作,但是如问题中所述,您至少可以尝试手动添加此代码,并查看它是否具有所需的效果。
答案 1 :(得分:0)
错误消息正在欺骗。在FVZServicesClient中,有一种方法希望通过引用传递参数。
public ScanBatchItemType[] CheckBatch(ref ScanBatchItemType[] scanBatchItemTypes)
我没有通过裁判。一旦我更正了该错误消息就消失了。目前,FVZServicesClient上没有COMVisibility或ClassInterface属性,COM可以。