Can I generate COM visible assemblies (using CodeDom, or anything else) ?
I am looking to expose C# classes to VBA. Basically, I have an object-driven web server, and everytime I build my web server, I would like to also generate some wrapping classes (COM visible using CodeDom) as some clients will need these to access data from other contexts (Excel/VBA, etc…).
So is this possible at all ?
UPDATE:
Trying the RegFree approach of Snoopy, I build that class into test2.dll with CodeDom:
namespace Test
{
public class TestClass
{
private double _d1;
private double _d2;
public double d1 {
get {
return _d1; }
set { _d1 = value; }
}
public double d2 {
get { return _d2; }
set { _d2 = value; }
}
public double sum()
{
return d1 + d2;
}
}
}
I get the following in VBE:

Yes, this is possible using Register Free COM.
1)Open Excel and add the following references
C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoree.tlb (Common Language Runtime Execution Engine 2.4 Library)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\ mscorlib.tlb
Add your Code Dom generated Classlibrary to the same directory where the Excel Sheet is stored
3)use the following VBA Code:
Sub Command1_Click() Dim clr As CorRuntimeHost Dim domain As AppDomain Dim objTest As Object Dim fltResult As String Set clr = New CorRuntimeHost clr.Start clr.GetDefaultDomain domain Set objTest = domain.CreateInstanceFrom("C:\Bla\YourGeneratedClassLibrary.dll", "NetComClassLibrary.Info").Unwrap fltResult = objTest.Version clr.Stop '//Debug.Print fltResult MsgBox fltResult End SubMore infos:
http://blogs.msdn.com/b/junfeng/archive/2006/04/20/579748.aspx