By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Com-Visible .net 4.0 assembly with PowerBuilder 9

Ravi L
P: 12
Hi There,(Com-Visible .net 4.0 assembly with PowerBuilder 9)

I have a peculiar issue with .net 4.0 assembly which is com-visible. We have a requirement where a powerbuilder application is supposed to invoke a method from a .net 4.0 assembly (dll). The following code is making the .net 4.0 dll com-visible.

<ComVisible(True)> _

<ClassInterface(ClassInterfaceType.AutoDual)> _

<ProgId("NamesSpace.ClassName")> _

<Guid("123412EB-ABCD-46C8-A902-123AC6EB466E")> _

<Serializable()> _

Public Class ClassName

It works perfectly when built using .net 2.0. but fails when using .net 4.0. when we try to connect to the assembly from powerbuilder it fails to connect and errors our with a "Cannot create an object" error. We tried building from a different machine and found that when built from a different machine even the .net 4.0 com-visible component works. It is able to connect.

The issue now is "The com-visible .net 4.0 assembly works when built from some machines and does not work when built from other machines." what may be the reason for this.

Any light on this will be really appreciated.

Thank you in advance.
Mar 15 '12 #1

✓ answered by Ravi L

Got this working. Posting the solution I got. It may help somebody in distress.

Declare an interface as below:
Expand|Select|Wrap|Line Numbers
  1. <InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
  2. Public Interface _IInterfaceName
  3. <DispId(1)> Function FunctionName(ByVal parameter As String) As ReturnType
  4. End Interface
  5.  
Now the functions to be exposed via COM will be in the class as below:

Expand|Select|Wrap|Line Numbers
  1. Public Class ClassName
  2.        Implements _IInterfaceName
  3.  
  4. Public Function FunctionName(ByVal parameter As String) As ReturnType Implements _IInterfaceName.FunctionName
  5.  
  6. 'Function Implementation
  7.  
  8. End Function
  9. End Class
  10.  
Hope this helps.

Share this Question
Share on Google+
1 Reply


Ravi L
P: 12
Got this working. Posting the solution I got. It may help somebody in distress.

Declare an interface as below:
Expand|Select|Wrap|Line Numbers
  1. <InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
  2. Public Interface _IInterfaceName
  3. <DispId(1)> Function FunctionName(ByVal parameter As String) As ReturnType
  4. End Interface
  5.  
Now the functions to be exposed via COM will be in the class as below:

Expand|Select|Wrap|Line Numbers
  1. Public Class ClassName
  2.        Implements _IInterfaceName
  3.  
  4. Public Function FunctionName(ByVal parameter As String) As ReturnType Implements _IInterfaceName.FunctionName
  5.  
  6. 'Function Implementation
  7.  
  8. End Function
  9. End Class
  10.  
Hope this helps.
May 9 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.