Automation error referencing .net dll from com (com interop) 
Author Message
 Automation error referencing .net dll from com (com interop)

OK, in my first foray into the .net world, I'm lost without a map...
I built a dll (which compiled and registered without a problem) for
sending SMTP email.  But, when I try to use it in a VBA app (just a
test Access app in this case), I get the following error: Run-time
error '-2146233082 (80131506)': Automation Error.  I've proven that I
can use .net dll's as I've used simpler ones with no problems, but on
this I'm stuck and can't see past it.  My code follows:

code from Email.vb

Imports System
Imports System.Web.Mail

Public Class Email
    Private mstrSendTo As String
    Private mstrSendFrom As String
    Private mstrCC As String
    Private mstrSubject As String
    Private mstrBody As String
    Private mstrAttachment As String
    Const SMTPServer As String = "stork"

    Public Property SendTo() As String
        Get
            Return mstrSendTo
        End Get
        Set(ByVal Value As String)
            mstrSendTo = Value
        End Set
    End Property

    Public Property SendFrom() As String
        Get
            Return mstrSendFrom
        End Get
        Set(ByVal Value As String)
            mstrSendFrom = Value
        End Set
    End Property

    Public Property CC() As String
        Get
            Return mstrCC
        End Get
        Set(ByVal Value As String)
            mstrCC = Value
        End Set
    End Property

    Public Property Subject() As String
        Get
            Return mstrSubject
        End Get
        Set(ByVal Value As String)
            mstrSubject = Value
        End Set
    End Property

    Public Property Body() As String
        Get
            Return mstrBody
        End Get
        Set(ByVal Value As String)
            mstrBody = Value
        End Set
    End Property

    Public Property Attachment() As String
        Get
            Return mstrAttachment
        End Get
        Set(ByVal Value As String)
            mstrAttachment = Value
        End Set
    End Property

    Public Function Send()
        Dim objMail As New MailMessage()

        objMail.From = mstrSendFrom
        objMail.To = mstrSendTo
        objMail.Subject = mstrSubject
        objMail.Cc = mstrCC

        objMail.BodyFormat = MailFormat.Text
        objMail.Body = mstrBody

        objMail.Priority = MailPriority.Normal

        If Not mstrAttachment Is Nothing Then
            'Add attachment to e-mail
            Dim objAtt As New MailAttachment(0)
            objMail.Attachments.Add(objAtt)
        End If

        SmtpMail.SmtpServer = SMTPServer
        SmtpMail.Send(objMail)
    End Function

    Public Sub New()
        MyBase.New()
    End Sub
End Class
______________________
code from Access app

Public Sub Test()
Dim oEmail As Email.Email
Set oEmail = New Email.Email
With oEmail


  .Subject = "testing"
  .Body = "Test body"
  .Send
End With

Set oEmail = Nothing

End Sub
_______________________

Any help is appreciated.

Thanks,

Dan



Tue, 17 Aug 2004 08:56:37 GMT  
 Automation error referencing .net dll from com (com interop)
I tried this code from a VB6 application and an Access application and it
appears to function correcly.  Have you tried using the class library from
a .NET application to see if any other errors pop up.

 Thank You,
 Dale Roberson
 Microsoft Developer Support

 This posting is provided "AS IS" with no warranties, and confers no rights.
 You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.



Tue, 17 Aug 2004 23:04:17 GMT  
 Automation error referencing .net dll from com (com interop)
I wrote a small .net executable and it ran fine from there, but I
couldn't get it to work in any VBA (Office 2000) application.  Also,
just to clarify, the error doesn't happen until the line where the VBA
app tries to instantiate the object.  It seems to me it should work
too...BTW, are .net components that are referenced via COM always
pointing to the .tlb (or maybe it's a .tbl file), versus the .dll
file?  In my other tries the component that showed in the reference
list always points to the .tlb (or .tbl) file...just wondering.

- Dan


Quote:
> I tried this code from a VB6 application and an Access application and it
> appears to function correcly.  Have you tried using the class library from
> a .NET application to see if any other errors pop up.

>  Thank You,
>  Dale Roberson
>  Microsoft Developer Support

>  This posting is provided "AS IS" with no warranties, and confers no rights.
>  You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
> reserved.



Wed, 18 Aug 2004 01:14:10 GMT  
 Automation error referencing .net dll from com (com interop)
Yes, it will point to a tlb.  This is what gives you the intellisense.  
What happens behind the scenes is that a file called mscoree.dll is loading
which in turn makes calls to the managed dll.

The only difference in my case is I was coding in Office XP apps.

Let's run through some steps.

Create a new Class Library project.
Delete the default class that gets created.
Right click the project and Add a New Item.
Select a COM class item to add and name it Email.vb
Reference the System.Web.dll file.
Add the Imports statements at the top of the new COM class.
Add the code you sent in here.
Right click the project and select the properties option
Open the Configuration Properties folder on the left.
Select Build option
Place a check mark in the Register for COM Interop option on the right.
Build the solution.

Try the VBA again against the new library.

 Thank You,
 Dale Roberson
 Microsoft Developer Support

 This posting is provided "AS IS" with no warranties, and confers no rights.
 You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.



Wed, 18 Aug 2004 02:56:37 GMT  
 Automation error referencing .net dll from com (com interop)
Thanks Dale, I went through the steps exactly as you said and it
worked like it should have.  I think I was renaming the class after I
had created it and/or not using the COM class template (not sure why
either of those would prevent it from working, but hey, I'm happy it's
working).

Finding clear-cut information that walks through .net examples like
this seems like it'd be easy to find, but in my searches of msdn
online, the newsgroups and other websites I haven't found a
comprehensive source.  Can you recommend (either from a MS standpoint
or personal) a good book for digging into VB.net and the differences
from old style VB to VB.net.  I'm thinking about either 1. Coding
Techniques for Microsoft Visual Basic.net - John Connell - ISBN #:
0735612544 or 2. Visual Basic.Net: How To Program - Harvey Deitel, et
al - ISBN #: 0130293636

Any recommendation would be appreciated.

Thanks,

Dan


Quote:
> Yes, it will point to a tlb.  This is what gives you the intellisense.  
> What happens behind the scenes is that a file called mscoree.dll is loading
> which in turn makes calls to the managed dll.

> The only difference in my case is I was coding in Office XP apps.

> Let's run through some steps.

> Create a new Class Library project.
> Delete the default class that gets created.
> Right click the project and Add a New Item.
> Select a COM class item to add and name it Email.vb
> Reference the System.Web.dll file.
> Add the Imports statements at the top of the new COM class.
> Add the code you sent in here.
> Right click the project and select the properties option
> Open the Configuration Properties folder on the left.
> Select Build option
> Place a check mark in the Register for COM Interop option on the right.
> Build the solution.

> Try the VBA again against the new library.

>  Thank You,
>  Dale Roberson
>  Microsoft Developer Support

>  This posting is provided "AS IS" with no warranties, and confers no rights.
>  You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
> reserved.



Sat, 21 Aug 2004 04:36:10 GMT  
 Automation error referencing .net dll from com (com interop)
Coding Techniques is pretty good.  The Upgrading VB6 to VB .NET (ISBN
0-7356-1587-X) is also pretty good.  I haven't evaluated any of the others.
 Also, don't discount the C# books.  Remember, both languages use the
framework and therefore how to accomplish tasks are relatively the same.  
The big difference is the syntax.  I'm finding the more I code, the more I
just switch back and forth between the languages just for fun.

 Thank You,
 Dale Roberson
 Microsoft Developer Support

 This posting is provided "AS IS" with no warranties, and confers no rights.
 You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.



Sat, 21 Aug 2004 23:29:12 GMT  
 Automation error referencing .net dll from com (com interop)

Quote:
> Yes, it will point to a tlb.  This is what gives you the intellisense.  
> What happens behind the scenes is that a file called mscoree.dll is loading
> which in turn makes calls to the managed dll.

> The only difference in my case is I was coding in Office XP apps.

> Let's run through some steps.

> Create a new Class Library project.
> Delete the default class that gets created.
> Right click the project and Add a New Item.
> Select a COM class item to add and name it Email.vb
> Reference the System.Web.dll file.
> Add the Imports statements at the top of the new COM class.
> Add the code you sent in here.
> Right click the project and select the properties option
> Open the Configuration Properties folder on the left.
> Select Build option
> Place a check mark in the Register for COM Interop option on the right.
> Build the solution.

> Try the VBA again against the new library.

>  Thank You,
>  Dale Roberson
>  Microsoft Developer Support

>  This posting is provided "AS IS" with no warranties, and confers no rights.
>  You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
> reserved.

Hi,

I tried above steps to access .net dll in my vb application. It is
again showing automation error in vb6.0 when object get instantiate.
So, what will be the solution for this?.

Regards,
Surendar.



Wed, 01 Sep 2004 18:13:18 GMT  
 Automation error referencing .net dll from com (com interop)
The steps above should work.  We need more details on what you are trying
to do.

 Thank You,
 Dale Roberson
 Microsoft Developer Support

 This posting is provided "AS IS" with no warranties, and confers no rights.
 You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.



Fri, 03 Sep 2004 21:27:10 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Unregisterable COM/AciveX DLL - Interop in VS.NET

2. Severe VB.NET COM/.NET Interop Limitation

3. COM / .NET interop

4. VB.NET COM Interop -vs- VB6 ---- The Turtle And The Hare

5. .Net browser control wrapper...will there be one?, com interop is crap

6. .NET to COM Interop with VSS - Deployment Question

7. .net interop with COM

8. Problem passing VB COM+ ASP Request object to .NET component System.Web.HTTPRequest through COM interop

9. COM Interop - using .NET component in VC6 client app

10. NET COM interop on CL

11. VB.NET COM interop debugging

12. Microsoft: PLEASE ADDRESS THIS (VB.NET COM Interop)

 

 
Powered by phpBB® Forum Software