2

I implemented a .NET DLL with COM visibility (VB.NET):

Public Class Processer Implements IProcesser
    Public Sub processASpecificThing(ByVal param As String) _
        Implements IProcesser.processAThing
        ' [...]
    End Sub
End Class

Below the Interface definition. For some reasons I exposed a method with a different name in the interface.

Imports System.Runtime.InteropServices
Imports System.ComponentModel

<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IProcesser
    Sub processAThing(ByVal param As String)
End Interface

The project is configured to set the Assembly as COM visible. If I understood correctly InterfaceIsDual let the Interface be visible at early binding as well as at late binding.

In a VB6 project, this works:

Dim aProcesser as IProcesser
Set aProcesser = New Processer
aProcesser.processAThing "param" ' Call by the *Interface* method name

In a VB6 project or an ASP classic VBScript page, this fails:

Dim aProcesser
Set aProcesser = CreateObject("ProcessLib.Processer")
' Call by the *Interface* method name
aProcesser.processAThing "param" ' [FAIL]           
' Call by the *Interface* method name
aProcesser.processASpecificThing "param" ' [SUCCESS]

The failing line leads to the error message:

Object Doesn't Support this Property or Method

The real context of this question is an ASP classic page. I use a late binding to avoid adding a METADATA header in the ASP file (I believe it's the only way, but not tested yet).

Sounds like the interface is not accessible. Why does that problem occur and how could I make the interface accessible with ?

Amessihel
  • 5,891
  • 3
  • 16
  • 40
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/193173/discussion-on-question-by-amessihel-com-visible-assembly-object-method-not-acc). – Jean-François Fabre May 10 '19 at 22:04
  • I would assume that this is related to how VB classic manages classes and interfaces, where in addition to explicitly-declared interfaces, there are also implicit interfaces that are automagically created for each class definition. Thus, the default interface used to access `ProcessLib.Processor` is the automatic interface, not `IProcessor` (you would have to specifically ask for that type, as happens with `Dim aProcessor As IProcessor`). And (as should not be surprising) the automatic interface exposes `processASpecificThing`. – Craig May 13 '19 at 14:37
  • (I don't have any familiarity with how .NET, or for that matter VB Classic, might be instructed to expose a specific interface for `CreateObject` for scripting languages.) – Craig May 13 '19 at 14:43
  • Thanks @Craig. Here is the summary of the discussion with Simon Mourier, greetings to him: basically InterfaceIsDispatch (and InterfaceIsDual too) allows method binding by name, which is needed for late binding usage. InterfaceIsDual allows also the default binding by index. If I wanted only a late binding use, I could have let .NET doing the job. Declared Interface I used is useful only for early bindings (and VB6 autocompletion). For both bindings I should have named class and interface methods the same way. – Amessihel May 13 '19 at 20:55
  • 1
    The problem is that the class has *two* interfaces. One is auto-generated and is used by any language that uses late-binding, it is the default interface that a scripting client sees. You need to suppress that default interface so the one you like becomes the default interface. Apply the `` attribute to the class. – Hans Passant May 14 '19 at 09:03
  • @HansPassant, and I would be able to call the method `aProcesser.processAThing` right after a call to `CreateObject("ProcessLib.Processer")`? – Amessihel May 14 '19 at 09:29
  • You can use any method or property exposed on the default interface. When your class has only one interface then you don't have to worry about what interface that might be, it will be IProcessor. Universal advice is to always use the ClassInterface attribute when you write the interface explicitly. – Hans Passant May 14 '19 at 09:38
  • Linking [this answer](https://stackoverflow.com/a/1436814/4375327) which provides more details about @HansPassant answer. – Amessihel Jun 18 '20 at 23:38

0 Answers0