title: My C# COM Library Isn't Working Right; Can't Instantiate The Class and a Method Appears As a Property
body: <p>I'm writing a COM DLL in C# to handle the import and export of X.12 format documents, so I would be able to use it in an Access database and a custom program for handling EDI with my company. I've gotten a DLL to compile but with disappointing results, and I'm wondering if I'm missing something; COM "from scratch" is new ground to me (I've made a ribbon for Excel before but a wizard handled all of that).</p>
  
  <p>I've read <a href="http://msdn.microsoft.com/en-us/library/c3fd4a20" rel="nofollow noreferrer">this article on MSDN</a> and came across <a href="https://stackoverflow.com/questions/853553/warning-msb3391-dll-does-not-contain-any-types-that-can-be-unregistered-for-co">this question here</a> to get my DLL and TLB to compile and register. This is the skeleton of my X12Segment class and the interface for COM visibility:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Collections;
  using System.Linq;
  using System.Runtime.InteropServices;
  using System.Text;
  
  namespace X12
  {
      [Guid("28A76274-05EE-45B2-A8EF-ADD5A5B351DE"),
      ComVisible(true)]
      public interface IX12Segment
      {
          [DispId(1)]
          string SegmentType { get; set; }
          [DispId(2)]
          string[] Fields { get; set; }
          [DispId(3)]
          char FieldDelimiter { get; set; }
          [DispId(4)]
          char SegmentDelimiter { get; set; }
          [DispId(5)]
          string ToString(char sep, char eol);
          [DispId(6)]
          string ToString();
          [DispId(7)]
          Type GetFieldEnum();
      }
  
      [Guid("B321599A-E5EC-4510-A021-E9A8B4D6293E"),
      ClassInterface(ClassInterfaceType.None),
      ComVisible(true)]
      public class X12Segment : IX12Segment
      {
          private string _type;
  
          protected ArrayList _fields;
          protected short _minFields = -1;
          protected short _maxFields = -1;
          protected short[][] _fieldSizes = { new short[] { -1, -1 } };
          protected char _sep;
          protected char _eol;
  
          public enum Field { }
  
          /// &lt;summary&gt;
          /// Creates a new X.12 segment of the supplied type,
          /// optionally with a supplied number of fields or
          /// values.
          /// &lt;/summary&gt;
          /// &lt;param name="segType"&gt;The type of segment (eg "ISA", "GS")&lt;/param&gt;
          /// &lt;param name="fields"&gt;Each string is a field
          /// within the segment&lt;/param&gt;
          public X12Segment(string segType, params string[] fields)
              : this(segType)
          {
              //Do cool stuff
          }
  
          /// &lt;summary&gt;
          /// Creates a new X.12 segment from a string.
          /// &lt;/summary&gt;
          /// &lt;param name="segType"&gt;The type of segment (eg "ISA", "GS")&lt;/param&gt;
          /// &lt;param name="segment"&gt;The string to parse&lt;/param&gt;
          public X12Segment(string segType, string segment)
              : this(segType)
          {
              //Do cool stuff
          }
  
          /// &lt;summary&gt;
          /// Creates a new X.12 segment of the supplied type,
          /// optionally with a supplied number of fields or
          /// values.
          /// &lt;/summary&gt;
          /// &lt;param name="segType"&gt;The type of segment (eg "ISA", "GS")&lt;/param&gt;
          /// &lt;param name="fieldCount"&gt;The number of fields
          /// in this segment&lt;/param&gt;
          public X12Segment(string segType, int fieldCount) : this(segType)
          {
              //Do cool stuff
          }
  
          /// &lt;summary&gt;
          /// Creates a new X.12 segment of the supplied type,
          /// optionally with a supplied number of fields or
          /// values.
          /// &lt;/summary&gt;
          /// &lt;param name="segType"&gt;The type of segment (eg "ISA", "GS")&lt;/param&gt;
          public X12Segment(string segType) : this()
          {
              //Do cool stuff
          }
  
          public X12Segment()
          {
              //Do cool stuff
          }
  
          /// &lt;summary&gt;
          /// Gets or sets the segment type.
          /// &lt;/summary&gt;
          public string SegmentType
          {
              get;
              set;
          }
  
          /// &lt;summary&gt;
          /// Gets or sets all of the fields in the segment,
          /// in the form of an array of strings.
          /// &lt;/summary&gt;
          public string[] Fields
          {
              get;
              set;
          }
  
          /// &lt;summary&gt;
          /// Gets or sets the character used to seperate fields in the segment.
          /// &lt;/summary&gt;
          public char FieldDelimiter
          {
              get;
              set;
          }
  
          /// &lt;summary&gt;
          /// Gets or sets the character denoting the end of the segment.
          /// &lt;/summary&gt;
          public char SegmentDelimiter
          {
              get;
              set;
          }
  
          /// &lt;summary&gt;
          /// Generates an X.12 formatted segment.
          /// &lt;/summary&gt;
          /// &lt;param name="sep"&gt;The field delimiter to use.&lt;/param&gt;
          /// &lt;param name="eol"&gt;The segment delimiter to use.&lt;/param&gt;
          /// &lt;returns&gt;An X.12 formatted string.&lt;/returns&gt;
          public string ToString(char sep, char eol)
          {
              //Do cool stuff
          }
  
          /// &lt;summary&gt;
          /// Generates an X.12 formatted segment.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;An X.12 formatted string.&lt;/returns&gt;
          public override string ToString()
          {
              //Do cool stuff
          }
  
          /// &lt;summary&gt;
          /// Returns the Type associated with the Field enumeration of this object.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;A System.Type of this object's Field enumeration.&lt;/returns&gt;
          public virtual Type GetFieldEnum()
          {
              //Do cool stuff
          }
      }
  }
  </code></pre>
  
  <p>Now, when I open up VBA and add the reference, the class shows up in IntelliSense. However, when I Dim a variable with the X12Segment type, then put in the dot operator, the IntelliSense window that pops up shows me that ToString() is a property, not a method. Also, ToString's overload shows up as ToString_2. When I attempt <code>Set seg = New X12Segment</code>, VBA tells me that it's an invalid use of the New keyword.</p>
  
  <p>What am I missing here?</p>
  
  <h2>Update</h2>
  
  <p>I've revised my code as per the comments and answer below, and I have solutions for <code>New</code> not working and my ToString overload appearing funky in IntelliSense. A new problem arises, though; trying to access Fields gives me errors. <code>seg.Fields = someStringArray</code> gets me an error saying "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic".</p>