Creating a DLL in CSharp in .Net

Posted on 2011-10-20
Last Modified: 2013-12-16

I am trying to learn about create DLL's in CSharp. I came across the following website page and was trying to replicate the example. I have named my project "LibTest".

In my folder C:\Users\user\Documents\Visual Studio 2008\Projects\Mine\LibTest\LibTest\bin\Debug I have two files, LibTest.dll and LibTest.pdb.

The issue I have is that Excel will not let me add the refence when I select the above dll file, the error message says "Cannot load reference".

I have ticked both "Make Assembly  COM-Visable" & "Register for COM Interop".

I have no idea what, how or if I need to use RegAsm.exe?

As always thanks for any help,

Question by:mcs26
    LVL 9

    Accepted Solution

    Yes you will have to use RegAsm.exe

    compile your dot net dll

    %comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86

    Open in new window

    visual studio command prompt will appear

    use the RegAsm.exe
    regasm /tlb:LibTest.tlb "C:\Users\user\Documents\Visual Studio 2008\Projects\Mine\LibTest\LibTest\bin\Debug\LibTest.dll"

    Open in new window

    This will create LibTest.tlb add the reference of this file.

    Author Comment

    Hi Sachin,

    Thanks for the reply. I will try your suggestion when I get home this evening as sadly my work place does not have microsoft visual studio's. I am using Visual Studio 2008 so guessing the path you supplied above will be the same bar the 2010 part?

    What excatly does the RegAsm.exe do then as I thought by ticking the ""Register for COM interop" that excel should be able to reference the dll file.

    Also where would I find the codebase file folder highlighted in the example?

    Many thanks

    Author Comment

    Hi just trying the commands. The error message I get is that I must have admistrative credentials. This is my laptop so how do I do this via the command prompt?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now