Solved

deploy com-enable C# ,.Net dll to workstation

Posted on 2014-03-07
1
641 Views
Last Modified: 2014-03-07
I am trying to write a com-enabled .Net DLL in C#, using the .Net 3.5 framework, and on my development machine I can use it in VBA (Excel) like this:

Public Sub try()
    Dim CR As CRPassThroughCOM.Main
    Set CR = New CRPassThroughCOM.Main
   
    Dim tryit As Boolean
    tryit = CR.Report
   
   
   
End Sub

I did notice that when I added the dll to the references, that it pointed to the debug folder, not the release folder.

I then sent the dll (from the release folder) to a personal machine that does not have the development environment.  I registered it with regasm, which on that machine was in the .Net 4.0 framework folder.  I used the /tlb and /codebase switches.

On the personal machine, in Excel VBA I can choose the reference, etc.  However, at tryit = CR.Report, it fails.  Intellisense does not see that method and it won't run.

The DLL looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CRPassThroughCOM
{
    public interface IMain
    {
        bool Report();
    }

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class Main : IMain
    {

        public Main()
        {
        }


        [ComVisible(true)]
        public bool Report()
        {
            try
            {
                MessageBox.Show("We are good, I guess");
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);//TODO: take this out
                return false;
            }
        }
    }
}

Any ideas what I can do to troubleshoot this?  I had to mark the assembly Make Assembly com-Visible to get this method to show up even on the development machine.

Thanks
0
Comment
Question by:g_johnson
1 Comment
 
LVL 4

Accepted Solution

by:
g_johnson earned 0 total points
ID: 39913607
I added in the Guids, and this now works.

    [Guid("62021e3e-5a49-4ccb-b059-3cd1a1421390")]
    public interface IMain
    {
        bool Report();
    }

    [Guid("a5295c27-8054-422b-a6ef-12670a890062")]
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class Main : IMain
    {
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question