Creating DLLs in .NET (C#) for to use in legacy environments

Posted on 2007-07-19
Last Modified: 2010-04-14
How do I create a DLL in .NET 2005 C# such that it can be referenced in legacy environments like VB6 and Delphi 7.  When I try to import normally compiled class libraries created in .net they cause in error in older environments.
Question by:fbk2000
    LVL 52

    Accepted Solution

    You need to go into the project properties and set the "Register for COM interop" flag on the "Build" tab. When you build the assembly it will be given a COM callable wrapper which will then allow you to use it like any other COM library.
    LVL 7

    Assisted Solution

    Checking the "Register for COM interop" is a beginning but not the entire solution
    Everytime I must do it I have to search the internet myself for the exact things to set.
    The problem is not making something COMVisible - the main problem lies in that you need to attribute all the necessary GUID's for ClassID's on Interfaces, Classes  and eventhandlers.

    A quick search revealed this article that has a nice working example (don't forget to read the update lower on the page where the author corrects a mistake he made in his code and definitely ignore the part on which he hails VB.NET for the better handling of COM ;-) )

    In general if you want to make a COM Visible class:
    Create the interface with all the properties, methods and events you want to expose
    Apply the correct attributes to attribute the different GUID's.
    Implement your interface and build as usual. Sign the assembly and make it installable in the GAC and  after installing in the GAC you have a fully working COM object. The GAC thing is not really necessary but most of the time if you make a COM object you want to make it available over the entire computer and not private to a project.

    Kind regards,

    Kind regards,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now