Shalom Levi and me have been in need to be able to write a com component in our C# team to be able to use it in an ASP page from a legacy system we have here.
This system needed to connect to an ldap server so we wrote the COM component in C#.
We struggled with the creation of the interface and the code while using examples like
Building COM Objects in C# from CodeProject.com.
both of them made the same kind of code assumption of creation of an interface implementing IDispatch and implementation of the interface in a class.
public interface DBCOM_Interface
void Init(string userid , string password);
bool ExecuteSelectCommand(string selCommand);
void ExecuteNonSelectCommand(string insCommand);
string GetColumnData(int pos);
// Events interface Database_COMObjectEvents
public interface DBCOM_Events
public class DBCOM_Class : DBCOM_Interface
private SqlConnection myConnection = null ;
SqlDataReader myReader = null ;
they allso talk about creating a strong name like this
sn -k Database_COM_Key.snk
and adding to the assembly the strong name
this is all good and true but missing some extra work we had to do.
first of all we simplified the source code like this:
public interface _LDAPSeq
bool IsAuthenticated(int IDCode,int IDNumber,string password);
public class LDAPSeq : _LDAPSeq
we also made a strong named .snk file and added it to the assembly then we went along and installed the DLL in the GAC.
gacutil /i LDAPSeq.dll
now it works flawlessly.
though we had a few more things to do it now works as a COM object
if you ever encounter problems with the .Net to COM you need to look at Show Us Your blog post it has lots of information regarding the errors you might expect.
i hope this will help you guys out there when you get to the same point