Solved

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

Posted on 2014-03-07
1
636 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now