Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I "generate" COM visible assemblies?

Tags:

c#

com

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: enter image description here

like image 317
BuZz Avatar asked Jun 27 '26 18:06

BuZz


1 Answers

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.

like image 199
adrianm Avatar answered Jun 30 '26 08:06

adrianm