p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

aspx thread: How to make a .Net component as COM component??

Message #1 by "Uma Maheswari" <maheswarim@r...> on 19 Feb 2001 13:50:55 -0000

I developed a .Net component (dll) in C#.  I want 

to use that component in a VB application.

I converted the dll to typelibrary file using

>>>>>tlbexp filename.dll

Then, I registered the dll using the command

>>>>>regasm filename.dll

Then I referred the filename.tlb in the VB Application.

Created an instance of the class and tried to 

access an method inside it.  But when running the 

VB Application I get the following error,


Runtime Error

Unable to locate Assembly 'filename,ver=,Loc="",SN=null"  which is

the server for CLSID 'CAFF........'


Please help me to locate the error.




Message #2 by "kasthurit" <kasthurit@c...> on Tue, 20 Feb 2001 10:42:05 +0800
Hai uma,

Here's a simple example. Create a C# file called testcomserver.cs and put

the following in it:

using System;

namespace AndyMc


        public class CSharpCOMServer


                public CSharpCOMServer() {}

                public void SetName( string name ) { m_name = name; }

                public string GetName() { return m_name; }

                private string m_name;



Then compile the .cs file as follows:

csc /target:library testcomserver.cs

You should get a dll, which you register like this:

regasm testcomserver.dll /tlb:testcomserver.tlb

Now you need to create a client to test your .NET COM component. VBScript

will do - put the following in a file called comclient.vbs:

Dim dotNetObj

Set dotNetObj = CreateObject("AndyMc.CSharpCOMServer")

dotNetObj.SetName ("bob")

MsgBox "Name is " & dotNetObj.GetName()

and run the script like this:

wscript comclient.vbs

And hey presto you should get a message box displayed with the text "Name is


(Note that at the time of writing there seem to be some path issues with

accessing .NET classes as COM components - to avoid problems, run

comclient.vbs from the same directory as testcomserver.dll)



  Return to Index