Introduction
Creating a DLL using Visual C# is piece of cake. Believe me it's much easier than VC++.
I have divided this tutorial in two parts.
- Building a Class Library,
- Building a client application to test the DLL.
Part 1: Creating a Class Library (DLL)
Create an Empty Class Library Project
Select File->New->Project->Visual C# Projects->Class Library. Select your project name and appropriate directory using Browse button and click OK. See Figure 1.

Figure 1.
Project and Its files
The Solution Explorer adds two C# classes to your project. First is AssemblyInfo.cs and second is Class1.cs. We don't care about AssemblyInfo. We will be concentrating on Class1.cs. See Figure 2.

Figure 2.
The mcMath Namespace
When you double click on Class1.cs, you see a namespace mcMath. We will be referencing this namespace in our clients to access this class library.
- using System;
- namespace mcMath
- {
- /// <summary>
- /// Summary description for Class1.
- /// </summary>
- public class Class1
- {
- public Class1()
- {
- //
- // TODO: Add constructor logic here
- //
- }
- }
- }
Now build this project to make sure every thing is going OK. After building this project, you will see mcMath.dll in your project's bin/debug directory.
Adding Methods
Open ClassView from your View menu. Right now it displays only Class1 with no methods and properties. Let's add one method and one property. See Figure 3.

Figure 3.
Right-click on Class1->Add->Add Method... See Figure 4.

Figure 4.
C# Method Wizard pops up. Add your method name, access type, return type, parameters, and even comments. Use Add and Remove buttons to add and remove parameters from the parameter list respectively. I add one test method called mcTestMethod with no parameters. See Figure 5.

Figure 5.
I am adding one more method long Add( long val1, long val2 ). This method adds two numbers and returns the sum. Click Finish button when you're done. See Figure 6.

Figure 6.
The above action adds two method to the class and methods look like following listing:
- /// <summary>
- /// //This is a test method
- /// </summary>
- public void mcTestMethod()
- {
- }
- public long Add(long val1, long val2)
- {
- }
Adding Properties
Open C# Property Wizard in the same manner as you did in the case of method and add a property to your class. See Figure 7.

Figure 7.
This action launches C# Property Wizard. Here you can type your property name, type, and access. You also have options to choose from getting only, set only, or get and set both. You can even select if a property is static or virtual. I add a property Extra with public access and bool type and get/set option set. See Figure 8.

Figure 8.
After adding a method and a property, our class looks like Figure 9 in Class View after expanding the class node.

Figure 9.
If you look your Class1 class carefully, Wizards have added two functions to your class.
- /// <summary>
- /// //This is a test property
- /// </summary>
- public bool Extra
- {
- get
- {
- return true;
- }
- set
- {
- }
- }
Adding Code to the Class








Rikam PalkarPosted Jun 3, 2020, 1:13 AM
I like the GUI, for old time sake.
Sagar Pandurang KapPosted Dec 11, 2017, 12:53 AM
Both creating DLL and accessing are easy to do.
Sagar Pandurang KapPosted Dec 11, 2017, 12:52 AM
Awesome article.explained in very easy way.it is piece of cake.
R MinPosted Feb 18, 2017, 2:58 AM
Great article and exercise for someone learning c# and refreshing the FUNdamentals!
Ramesh PalaniappanPosted Aug 18, 2016, 8:18 AM
Nice
kalu singh raoPosted Jul 7, 2016, 8:39 AM
Nice...
Bhuvanesh MohankumarPosted Apr 19, 2016, 2:32 PM
Good one
Mohammad KhalidPosted Mar 25, 2016, 3:19 AM
Very nice and important article for new developers. You have made this article simple to understand by anyone.
Vignesh ManiPosted Feb 27, 2016, 2:52 PM
Good one
Sonu ChaudharyPosted Feb 25, 2016, 6:30 AM
good one
Anu VPosted Feb 22, 2016, 12:01 AM
good
Umarul FarookPosted Jan 22, 2016, 10:47 AM
this is really wow
Mukesh KumarPosted Oct 18, 2015, 1:42 AM
Great Article
Anil KumarPosted Sep 22, 2015, 5:49 AM
Thanks
Jyoti Ranjan SwainPosted Sep 12, 2015, 5:44 AM
THANKS SIR
Yashwanth MuthineniPosted Aug 22, 2015, 7:41 AM
Nice Article.
Nakul SharmaPosted Apr 4, 2015, 10:49 PM
Thank you so much sir!
Vijay MakwanaPosted Jul 16, 2014, 3:56 AM
Thank You..
Rinkal PatelPosted May 27, 2014, 2:56 PM
nice
Former memberPosted Dec 14, 2012, 11:48 AM
thanks nice article..
harun ahmedPosted Jun 15, 2012, 4:36 PM
nice article!!
JunPosted Apr 3, 2012, 4:28 PM
Hello, Mr. Chand I am working on a Window CE based project. I wnat to call a compact .NET DLL method from a compact .NET application both are on our handheld device. And the DLL resides in a folder different from the one where the application resides. I am developing the DLL and application on a desktop computer. When I build the application, I can use reference to the DLL. But on the device, how will I be able to load the DLL and call the method when the DLL is in a obscure folder. If I use Aseembly.LoadFrom() and then what can I do with it to call a method called aDLLMethod() of the DLL. Jun
yaquza yaquzaPosted Oct 25, 2011, 2:52 AM
hi i want import a dll file to my program.(note that i want import a external dll file to program, no build a dll file or class library in c#)
Gaurav KumarPosted Jun 4, 2011, 3:09 AM
Very very good article very helpful....
ILIIA CHTEREVPosted Mar 24, 2011, 12:06 PM
Hello Mahesh, Great article and easy example that helps to grasp a cool development idea. MS themselves do not have such thing although it would not hurt. Please help in my thinking. Say I have in development one class library project and one web application project. After adding reference in my Web App to the Class Libr Project I can see a copy of the Cl Li Pr's DLL into the Web App's Bin folder. Now, when I go to deploy my Web App to the Production Server - Do I need anything else exept that that DLL into my Web App's Bin folder. Is there something that shuld be doen with the original CLP. Does it just stay and help only on the Dev side. If I make some changes into the CLP (say that do not break the external methods' structure) can I just replace the CLP's DLL on the Prod server or again I need to replace both Web App's DLL with the CLP's DLL. Thank you very much.
sarika jainPosted Feb 14, 2011, 2:16 AM
Hello Sir,while rading this article i found this is an interesting article but when i am right clicking Class1.cs there is no option of Add.please help me in this
sarika jainPosted Feb 14, 2011, 2:14 AM
Hello Sir,while rading this article i found this is an interesting article but when i am right clicking Class1.cs there is no option of Add.please help me in this
lalit kumarPosted Jan 14, 2011, 7:12 AM
i m not understanding after adding the class libaray file in project... help me plzzz
raj guptaeditedPosted Oct 25, 2010, 10:48 AMEdited Nov 7, 2010, 4:30 PM
d
shravan kumarPosted Jul 23, 2010, 1:23 AM
how can i get class file from any .dll?can u send me procedure for it..
satish kumarPosted Jul 19, 2010, 7:00 AM
Thanks man u are a great help to me .
Johan LijffijtPosted Jul 15, 2010, 8:25 AM
Hi , Great example! I have been creating your example and it works fine in another program that uses vba like scripting. The only thing i see is that intellisense is not working. How can i make it work that after i enter a point i see all available methods? Thanks!
ostwal jainPosted Jul 8, 2010, 7:35 AM
but if i want to use combination of functions e.g if in class i wrote function for datafetch and exceutenonquery & i want to use it in my form such as Datafetch.Excetuenonquery() Then how to use it
ostwal jainPosted Jul 8, 2010, 7:35 AM
but if i want to use combination of functions e.g if in class i wrote function for datafetch and exceutenonquery & i want to use it in my form such as Datafetch.Excetuenonquery() Then how to use it
Former memberPosted May 10, 2010, 6:46 AM
ela ela keep it up machoo!
Arif HasanPosted Mar 1, 2010, 8:21 AM
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CArif%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--> Very helpful article
VenkatPosted Dec 22, 2009, 3:43 PM
I have Added a reference to this DLL from a project and deployed(copied exe to network frive) the exe I created from that project. Now if I change anything in the DLL, the exe is not picking up latest changes. What is the proper way of doing it. Thanks, Kaashi.
sameer ahmedPosted Sep 5, 2009, 5:13 AM
Weel Article Which solved my problem
Alan C BalkanyPosted Apr 30, 2009, 11:15 AM
C-sharpcorner regularly has helpful examples of basic C# techniques, without a lot of complexity. Thanks Mahesh!
Nancy NeiraPosted Oct 30, 2008, 12:45 AM
And your article saved my fiscal week! Thank you, thank you, n143juju
han weiPosted Jan 23, 2008, 11:13 PM
hi : how does the Assembly show its property's or method's tooltips just as system's assembly, when i use it in another project?
Natarajan KannaiyanPosted Jan 8, 2008, 8:58 AM
hi magesh how to pass dropdown object as argument in dll method in c# .net please help me.............
Natarajan KannaiyanPosted Jan 8, 2008, 8:56 AM
hi magesh how to pass dropdown object as argument in dll method in c# .net please help me.............
dan lamPosted Dec 15, 2007, 2:06 PM
When i build mcClient, how can i make it possible so that it builds the mcMath.dll into a folder say 'plugins' i.e in my bin\Debug\ i will have mcClient.exe and it build and call mcMath.dll from bin\Debug\plugin
dan lamPosted Dec 15, 2007, 2:05 PM
When i build mcClient, how can i make it possible so that it builds the mcMath.dll into a folder say 'plugins' i.e in my bin\Debug\ i will have mcClient.exe and it build and call mcMath.dll from bin\Debug\plugin
mohamed moussalamPosted Dec 15, 2007, 5:49 AM
I already have a dll file that i want to add in my C# project but when am adding a refernce it gives me this error "a reference to"my dll" could not be added .please make sure that the file is accessible,and that it is a valid assembly or a COM component." ? please infor me what to do thank you
Kunal MandloiPosted Dec 7, 2007, 12:45 AM
How can i view it
pejman amiriPosted Nov 13, 2007, 2:32 AM
hi i have one classlibrary and i want to use it in an application i whant to access my fnctions with progid but i am facing this error:unable to get clsid from progid
Ahmed ElmahdawyPosted Nov 5, 2007, 11:12 AM
how can i add a method in visual C# 2005? the menu that appears doesn't contains "Add > Method" button.
mahdieh taherPosted Oct 23, 2007, 2:07 AM
Hi, i want to see the implementation of a .dll file.implementation of methods. how can?
Fred FowlerPosted Oct 5, 2007, 4:18 PM
Mahesh, Just today I was wondering how to do this (new to C#) and shazaam here you are. Very clear and concise in such a short demonstration. Ususally something is lost in some of the shorter tutorials but I was able to implement this right after the tutorial. I see that you are an author and was wondering what other pearls of wisdom you have written and where can they be found. Thanks again
prasad prasadPosted Aug 30, 2007, 5:49 AM
add reference
prasad prasadPosted Aug 30, 2007, 5:47 AM
gfthy
T APosted Aug 24, 2007, 11:24 AM
Hi Mahesh, I created a dll and referred to it just like you said in your article. However, I get the error : The type or namespace name 'myDLL' could not be found (are you missing a using directive or an assembly reference?) I found an article saying I should use the "Project" tab in "Add Reference" to add my dll. I did and it's still not working. My DLL and Console apps are in the same Solution. Would you please give me a suggestion as how to fix the problem? Thanks, TA
T APosted Aug 24, 2007, 11:09 AM
Hi Mahesh, I created a dll and referred to it just like you said in your article. However, I get the error : The type or namespace name 'myDLL' could not be found (are you missing a using directive or an assembly reference?) I found an article saying I should use the "Project" tab in "Add Reference" to add my dll. I did and it's still not working. My DLL and Console apps are in the same Solution. Would you please give me a suggestion as how to fix the problem? Thanks, TA
Amila HettiarachciPosted Aug 21, 2007, 12:17 AM
Dear Mahesh Its a very simple and nice article. Can i add dll for a web site project. Thanks Amila
Luanne MarceloPosted Aug 15, 2007, 9:00 PM
Is it possible to use one dll on two applications running at the same time? Using dll let's say App1's output will be the input of App2. If yes, would you be kind to show me some examples. Thank you.
Luanne MarceloPosted Aug 15, 2007, 8:55 PM
Is it possible to use one dll on two applications running at the same time? Using dll let's say App1's output will be the input of App2. If yes, would you be kind to show me some examples. Thank you.
carlos santiagoPosted Jun 25, 2007, 10:09 AM
If you can tell me how to use a cs dll in visual basic 6 or were I can find information about it. Thanks.
PetereditedPosted May 23, 2007, 6:26 AMEdited May 23, 2007, 6:28 AM
Hello mahesh, I have created a dll with the help of your example code. My code is as following: using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace DRLAW { public class FolderDialog { public void OpenFolder() { FolderBrowserDialog FBDlog = new FolderBrowserDialog(); FBDlog.Description = "Selecteer de Benodigde map:"; FBDlog.ShowNewFolderButton = true; if (FBDlog.ShowDialog() == DialogResult.OK) { MessageBox.Show(FBDlog.SelectedPath, "Test", MessageBoxButtons.OK); } } } } but i cant register it with regsvr32'in windows Could you tell me what i am doing wrong ? Thanks for the help in advance Kind regards Peter
ali kazemiPosted May 22, 2007, 6:28 AM
How can i Make DLL From Cs file?
nazi bijoorianPosted Mar 30, 2007, 11:42 PM
How can I call a method and it's parameters from a library within a form for using that method and it's parameters to validate a text box
Michael LutzPosted Feb 11, 2007, 7:18 PM
how can i use this sample dll (mcMath.dll) with vba?
walter weberPosted Feb 1, 2007, 8:52 PM
How would you add the assembly inforation to a class like this. i have a simple class I am trying to use with Report Services. I have created a key pair, copied dll to correct directories and modified confi files. When I try to add the reference I am told it does not contain assembly information. Thanks
Muslim ModiPosted Jan 29, 2007, 2:01 AM
if i have to call McMath dll at run time then how can achieve this.