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
Suhredayan Panikkal - 21 Feb 2008 08:06 GMT
You need to give a GUID for .net framework class to behave like COM object.
use the GuidAttribute to associate a GUID, this is in
System.Runtime.InteropServices namespace.
The code should look like:
namespace MyPlugin
{
[Guid("690AB25B-4E76-4e5e-9DF3-39D5E7A08242")]
public interface IMyClass
{
bool Process(object session);
}
[Guid("274E67E5-6B00-4624-A721-782049101F91")]
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;
}
}
}
-Suhredayan
> Hi,
>
[quoted text clipped - 54 lines]
>
> Thanks
PLS - 26 Feb 2008 04:26 GMT
You need to mark you method ComVisible(true) also.
++PLS
In article <81f8d71a-f4cd-43e0-a950-eee046ef55d4
@s12g2000prg.googlegroups.com>, bzamfir@gmail.com says...
> Hi,
>
[quoted text clipped - 45 lines]
>
> The message seems ok.