Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2008

Tip: Looking for answers? Try searching our database.

Write COM component in C# 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bz - 18 Feb 2008 21:21 GMT
Hi,

I need to write a COM component in C# (VS 2005)
I created the C# class library project, marked it "Make Assemble COM
visible"
I set the assembly to be signed with a key file.
The class contains a single method, as below:

namespace MyPlugin
{
   public class MyClass
   {
       public bool Process(object session)
       {
           bool retVal = false;
           try
           {
               // some processing here
               retVal = true;
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error " + ex.Message);
           }
           return retVal;
       }
   }
}

I built the project and registered it with

c:\>regasm /tlb:mylib.tlb mylib.dll
Microsoft (R) .NET Framework Assembly Registration Utility
2.0.50727.1433
Copyright (C) Microsoft Corporation 1998-2004.  All rights reserved.

Types registered successfully
Assembly exported to (...)MyLib.tlb', and the type library was
registered success
fully

c:\>gacutil /i mylib.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version
2.0.50727.42
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

The message seems ok.

Still, in object browsert in VB6 or Access or other COM-enabled, I can
browse my class (by browsing the TLB) and I see only three methods
Equals, GetHashCode and GetType and a property ToString, but I cannot
see my method.

What am I doing wrong?

Thanks
Alvin Bruney [ASP.NET MVP] - 21 Feb 2008 03:04 GMT
I think this looks ok on a very quick glance. You'll need to add a default
constructor though and I don't see that in there. Another thing is to check
the assembly.cs file to see if comvisibility is actually set to true, the
IDE can be flaky and not update that flag. Or you can do this above your
class declaration [ComVisible(true)]

Signature

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------

> Hi,
>
[quoted text clipped - 54 lines]
>
> Thanks
bz - 07 Mar 2008 11:36 GMT
Thanks for answer
Actually I made it work in the end, (I had to restart IDE in between)
It might be something related with IDE

Regards

On 21 Feb, 05:04, "Alvin Bruney [ASP.NET MVP]" <www.lulu.com/owc>
wrote:
> I think this looks ok on a very quick glance. You'll need to add a default
> constructor though and I don't see that in there. Another thing is to check
[quoted text clipped - 72 lines]
>
> - Afişare text în citat -

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.