我的客户在全球范围内安装了一个VB6程序。现在需要通过REST API访问外部系统。我创建了一个VB.Net类库,针对.NET Framework 4进行了定位。(这是目前已经在各处安装的最新版本)。该DLL公开了约十几个公共函数和子例程以及约40个属性。我使用以下PowerShell代码测试了该DLL:
[System.Reflection.Assembly]::LoadFile( "$directorypath\Debug\MyExample.dll")
$quotaInstance = new-object MyExample.ComClass1
所有的方法和属性都可以从PS脚本中访问。然而,当我将DLL加载到VB6 IDE中时,对象浏览器只显示方法,而不是属性。如果我无法解决这个问题,我将不得不将它们重新编码为一堆函数和子程序。我讨厌那个想法。
问题如何在.NET DLL中使属性对COM可见(方法可以工作)看起来很相似,但我没有(明确地,请参见下文)使用接口,而且我不确定这个问题是否曾经得到回答。
有人知道发生了什么,并且(更重要的是)如何修复它吗?谢谢!
更新:人们要求看到我的代码,所以这里是一个简化的示例。我猜测由于InterfaceId,Visual Studio Community 2017正在为我创建某种接口。
<ComClass(Example.ClassId, Example.InterfaceId, Example.EventsId)>
Public Class Example
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "099bfc91-1f82-4a26-b1e0-d9645bb1714d"
Public Const InterfaceId As String = "13e9763d-455c-4d89-8323-cc4e7ae7648e"
Public Const EventsId As String = "773feeba-e635-4411-b175-30b345afa841"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
' *** Auto-implemented properties
' When you declare an auto-implemented property, Visual Basic automatically
' creates a hidden Private field called the backing field to contain the
' Property value. The backing field name is the auto-implemented Property
' name preceded by an underscore (_).
Public Property Foo As String
Public Property Bar As Integer
Public Function InitiateSession(ExampleServer As String) As Boolean
' Creates a new API_session.
' Returns True if the connection was successful, otherwise False
' ...
End Function
Public Sub CloseSession()
' Releases the current API_session.
' ...
End Sub
End Class