I am trying to create a Com Class dll in VB.Net 2008 which will be accessable from VBA and VB6.
I have choosen Class Library.
Then added a New COM Class
I deleted the original Class1 .vb
I added my code.
I added <Assembly: ClassInterface(ClassInterfaceType.AutoDual)> to my Com Class. It already had a ComClass entry
I made sure "Register for COM interopp" was checked in the project>properties>Compile screen.
After a build I move the .dll, .tlb and the snk to a server.
I would like to leave the dll on the server rather than install it on every workstation (but I could put it on every workstation if that is my problem).
Since I am also testing on the server I use RegAsm to register the assembly.
I have tried both
regasm M:\email\sendemail.dll /codebase M:\email\sendemail.dll
and
regasm M:\email\sendemail.dll /tlb:M:\email\sendemail.tlb /codebase M:\email\sendemail.dll
The second one overwrites the .tlb created by visual studio.
I even dragged the .dll into the C:\windows\assembly directory and unregistered the assembly.
Regardless of what I have tried, I cannot add the dll as a reference in Excel 2003.
The message I receive is:
"Can't add a refernce to the specied file"
I can add the .tld file. When I add the .tlb file I can see the properties and methods. But when I run the code I get ActiveX component cannot create object. (this is the error message I get when using the VS version of the.tlb. The message is different when I use the .tlb which is generated by the RegAsm.)
I have read many many google results but still nothing that has gotten me going.
It can't be this difficult. What am I missing???
thanks,
pat
Here is the code. I have removed all of the properties except for one and I have stripped everything out of the method, except the one line. I hope this helps.
Imports System.Net
Imports System.Net.Mail
Imports System.Runtime.InteropServices
'
<Assembly: ClassInterface(ClassInterfaceType.AutoDual)>
<ComClass(SendEmailClass.ClassId, SendEmailClass.InterfaceId, SendEmailClass.EventsId)> _
'
Public Class SendEmailClass
'
#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 = "187d8992-b211-44f7-9bf0-9be98129905c"
Public Const InterfaceId As String = "2ca24656-528b-42a2-bed0-a1452d70c0de"
Public Const EventsId As String = "e8f8d4e7-ee4d-47e8-8b30-765111c27ec0"
#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
'
Private ToStringM As String
'
Public Property ToAddressString() As String
Get
Return ToStringM
End Get
Set(ByVal Value As String)
ToStringM = Value
End Set
End Property
Public Sub SendMail()
Dim mail As New Mail.MailMessage
mail.To.Add(ToStringM)
End Sub
End Class