Click here to Skip to main content
13,588,593 members
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 31 Jul 2005

Using .NET Assembly with COM Client

, 31 Jul 2005
Rate this:
Please Sign up or sign in to vote.
This article explains about the .NET Interoperability with COM.

This article explains the step by step procedure of how to use a .NET Assembly with COM Client.

Step 1: Creating a .NET Assembly Project

Visual Studio .NET IDE -> File -> New Project ->
Visual Basic Projects -> Class Library

1.2 Name the Application, for instance NetServer, this will
be our .NET Assembly Project,which will be consisting of at
least one class called Class1.vb.

1.3 Rename the class to NetClass from properties window and manually
in code window.This class will hold all the functionality of .NET Component,
in the form of few functions.

Sample screenshot

Step 2: Adding Functionality

On the path of achieving COM Interoperability, Microsoft .NET
offers an attribute named <comclass()>,which is
located inside the Micrsoft.VisualBasic namespace
and it makes the .NET Class available for use by a COM Client.

It’s also a wise choice to add System.Runtime.InteropService namespace to the class, which offers various features to be used.

The figure below shows the whole Code of .NET Assembly.

Sample screenshot

Step 3: Set Property for COM Interoperability

Select NETServer project from Solution Explorer, Right Click ->
Properties -> Configuration Properties -> Build -> Check on
Register for COM Interop

After setting the property, do Build The Solution. It will create
a NetServer.dll (assembly) in your applications \bin folder.

Sample screenshot

Step 4: Deploying for COM access

A .NET assembly which has been created can’t be used by a COM Client,
because COM Client can access an object with help of a Type Library,
which tells to the Client about the Object.

In .NET world there is no such concept of Type LIbrary, but because of
COM Interop feature, .NET Framework SDK offers a tool called
RegAsm.Exe which offers to make a type library and
register it in Windows Registry, the very own style of COM.

4.1 Access Command Prompt (cmd)

4.2 Change the path to your application folder
for example : C:\>D: press enter
D:\> cd Net Applications\NetServer\Bin
D:\Net Applications\NetServer\Bin>

4.3 Type the following command to create a
Type Library,which is a COM world’s buzz word and equivalent
to Metadata of a .NET Assembly.

D:\Net Applications\NetServer\Bin> RegAsm /tlb: NetServer.tlb NetServer.dll

This command will create a Type Library named NetServer.tlb
in the \bin folder of .NET Assembly application. Which was
automatically registered in Windows Registry as well.

Now the .NET Assembly is ready to use by a COM Client.

Step 5: VB 6.0 Client to access .NET Assembly

5.1 Open Visual Studio 6.0 -> Visual Basic 6.0 ->
File -> New -> Standard.Exe

5.2 Drag one Label and two Command Buttons onto the form.

Sample screenshot

Step 6: Set Reference to the Type Library

Before consuming the class you build using .NET

Project -> References -> Find the NetServer and select that.

Sample screenshot

Step 7: Code to access the .NET Class

Sample screenshot

after adding the code, run your VB 6.0 and click on the command buttons, you will see that your application communicating with .NET Assembly.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Vidya Vrat
Web Developer
India India
Vidya Vrat Agarwal, a Microsoft .NET Purist, an MCSD.NET, MCAD, MCSD, MCT. I am also a Life Member of Computer Society of India (CSI). I started working on Microsoft.NET with its beta release. I have been involved in software development,corporate trainings, T3 programs, technical writing and consultation for Microsoft.NET for various corporate clients.

Presently I am working with LionBridge Technologies in Mumbai - India, with Microsoft Dept. on Whidbey and Yukon and my business card reads Subject Matter Expert (SME).

My technical profile holds
.NET Framework,VC#,VB.NET,WebServices,Remoting, SQL Server, COM, DCOM, COM+, MTS, MSMQ. Whidbey, Yukon and Longhorn.

My Blog can be read at

You may also be interested in...


Comments and Discussions

GeneralI have problem when i register .net assembly as COM to consume that in classic ASP Pin
lakshmin16-Apr-08 0:44
memberlakshmin16-Apr-08 0:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.180615.1 | Last Updated 1 Aug 2005
Article Copyright 2005 by Vidya Vrat
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid