Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a .NET COM+ dll

Tags:

c#

asp.net

dll

com

I have the following COM object installed on one of our servers that I need to rewrite...some legacy code uses the object as follows:

Set oEmail = CreateObject("SSDSCommunicator.EmailClass")
oEmail.Send(szFrom, szRecipients, szSubject, szEmailBody, SMTPServer, szErr, "", , , , True)

I have followed the example in this answer but I'm struggling to register the COM component.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mail;
using System.Runtime.InteropServices;


namespace SSDSCommunicator
{

    [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("DB38A91C-9EB6-4472-9A49-40722431E096")]
    public interface IEmailClass
    {
        void launch();
        bool Send(string szFrom, string szTo, string szSubject, string szMessage, string szSMTPServer, ref object szError, string szAttachments = "", string szReplyTo = "", string szCC = "", string szBCC = "", bool bHTMLBody = false);
    }

    [ClassInterface(ClassInterfaceType.None), Guid("A00C16DA-1791-4A3A-8D16-4765A9FAD060"), ProgId("SSDSCommunicator.EmailClass")]
    public class EmailClass : IEmailClass
    {
        private string path = null;

        public void launch()
        {
            Console.WriteLine("I launch scripts for a living.");

        }

        public bool Send(string szFrom, string szTo, string szSubject, string szMessage, string szSMTPServer, ref object szError, string szAttachments = "", string szReplyTo = "", string szCC = "", string szBCC = "",    bool bHTMLBody = false)
        {
    ...
        }

    }
}

The project builds successfully. How do I register the dll as a COM object so that the the old VB6 code will work?

I have ticked the register for COM interop and Make the assembly COM visible in the project settings.

I've had no luck with regsvr32 (no entry point found) or regasm...

The COM object looks like this on the old server:

enter image description here

Edit

Should I be able to see the COM object in component services after running the regasm command?

regasm C:\...\SSDSCommunicator.dll /CodeBase
like image 545
woggles Avatar asked Nov 04 '22 11:11

woggles


1 Answers

OK sweet...found the answer to this thanks to user957902 and GTG (write some answers below if you want points):

  • Built the solution targeting x86
  • Signed the assembly using an .snk file
  • Inherited ServicedComponent
  • Manually added the SSDSCommunicator component in component services and then added the dll as a component

Final code below:

 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.Mail;
    using System.Runtime.InteropServices;
    using System.EnterpriseServices;


    namespace SSDSCommunicator
    {

        [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("DB38A91C-9EB6-4472-9A49-40722431E096")]
        public interface IEmailClass
        {           
            bool Send(string szFrom, string szTo, string szSubject, string szMessage, string szSMTPServer, ref object szError, string szAttachments = "", string szReplyTo = "", string szCC = "", string szBCC = "", bool bHTMLBody = false);
        }

        [ClassInterface(ClassInterfaceType.None), Guid("A00C16DA-1791-4A3A-8D16-4765A9FAD060"), ProgId("SSDSCommunicator.EmailClass")]
        public class EmailClass : ServicedComponent, IEmailClass
        {
            private string path = null;           

            public bool Send(string szFrom, string szTo, string szSubject, string szMessage, string szSMTPServer, ref object szError, string szAttachments = "", string szReplyTo = "", string szCC = "", string szBCC = "",    bool bHTMLBody = false)
 {...
}

        }
    }
like image 117
woggles Avatar answered Nov 09 '22 12:11

woggles