WSDL 生成的类型不采用 COM 属性

WSDL generated type does not take COM attributes

我生成了一个 WSDL class

 [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 接口恰好使用了上面的 class。

当我用

注册程序集时
regasm MyAssembly.dll /tlb:MyAssembly.tlb

我收到错误消息

Microsoft .NET Framework Assembly Registration Utility version 4.7.3062.0 for Microsoft .NET Framework version 4.7.3062.0 Copyright (C) Microsoft Corporation. All rights reserved.

Types registered successfully Type library exporter warning processing 'MyAssembly.FVZServices.FVZServicesClient, MyAssembly'. Warning: Type library exporter encountered a type that derives from a generic class and is not marked as [ClassInterface(ClassInterfaceType.None)]. Class interfaces cannot be exposed for such types. Consider marking the type with [ClassInterface(ClassInterfaceType.None)] and exposing an explicit interface as the default interface to COM using the ComDefaultInterface attribute. Assembly exported to 'C:\Users\MyName\Documents\ScanLibrary\Packet\MyAssembly.tlb', and the type library was registered successfully

当我按照建议将属性 [ClassInterface(ClassInterfaceType.None)] 添加到 FVZServicesClient 时,我在下次尝试 regasm 时仍然收到相同的错误消息。我知道生成的代码可以随时被覆盖,但我用 DotPeek 验证了 ClassInterface-attribute 仍然在编译代码中。

我尝试的另一件事是创建具有 ClassInterface 属性的部分 class FVZServicesClient。如消息所示,我还使用 COMDefaultInterface 标记了默认接口。结果是一样的。为 FVZServicesClient 添加属性 [ComVisible(false)] 也没有帮助。

在VB6中引用库时,编译报错:"User-defined type not defined".

如何从 COM 接口中排除 FVZServicesClient?

尝试将属性 [ComVisible(false)] 添加到 class FVZServicesClient

我不确定您的代码生成过程是如何工作的,但正如问题中所述,您至少可以尝试手动添加它并查看它是否具有预期的效果。

错误消息是骗人的。在 FVZServicesClient 中有一个方法需要通过引用传递参数。

public ScanBatchItemType[] CheckBatch(ref ScanBatchItemType[] scanBatchItemTypes)

我没有通过裁判。一旦我更正了它,错误消息就消失了。目前 FVZServicesClient 上没有 COMVisibility 或 ClassInterface 属性,COM 可以接受。