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:

If you look at the documentation for ComVisibleAttribute it says
The default is true, which indicates that the managed type is visible to COM. This attribute is not needed to make public managed assemblies and types visible; they are visible to COM by default.
Then there are some restrictions like only public types with default constructor etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With