title: How to declare and implement a COM interface on C# that inherits from another COM interface?
body: <p>I'm trying to understand what is the correct why to implement COM interfaces from C# code. It is straightforward when the interface doesn't inherit from other base interface. Like this one:</p>
  
  <pre><code>[ComImport, Guid("2047E320-F2A9-11CE-AE65-08002B2E1262"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  public interface IShellFolderViewCB
  {
    long MessageSFVCB(uint uMsg, int wParam, int lParam);
  }
  </code></pre>
  
  <p>However things start to become weired when I need to implement an interface that inherits from other COM interfaces. For example, if I implement the <code>IPersistFolder2</code> interface which inherits from <code>IPersistFolder</code> which inherits from <code>IPersist</code> as I usually on C# code: </p>
  
  <pre><code>[ComImport, Guid("0000010c-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  public interface IPersist
  {
    void GetClassID([Out] out Guid classID);
  }
  
  [ComImport, Guid("000214EA-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  public interface IPersistFolder : IPersist
  {
    void Initialize([In] IntPtr pidl);
  }
  
  [ComImport, Guid("1AC3D9F0-175C-11d1-95BE-00609797EA4F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  public interface IPersistFolder2 : IPersistFolder
  {
    void GetCurFolder([Out] out IntPtr ppidl);
  }
  </code></pre>
  
  <p>The operating system is not able to call the methods on my object implementation. When I'm debugging I can see the constructor of my <code>IPersistFolder2</code> implementation is called many times, however the interface methods I've implemented aren't called. I'm implementing the <code>IPersistFolder2</code> as follows:</p>
  
  <pre><code>[Guid("A4603CDB-EC86-4E40-80FE-25D5F5FA467D")]
  public class PersistFolder: IPersistFolder2
  {
    void IPersistFolder2.GetClassID(ref Guid classID) { ... }
    void IPersistFolder2.Initialize(IntPtr pidl) { ... }
    void IPersistFolder2.GetCurFolder(out IntPtr ppidl) { ... }
  }
  </code></pre>
  
  <p>What seems strange is when I declare the COM interface imports as follow, it works:</p>
  
  <pre><code>[ComImport, Guid("0000010c-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  internal interface IPersist
  {
    void GetClassID([Out] out Guid classID);
  }
  
  [ComImport, Guid("000214EA-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  internal interface IPersistFolder : IPersist
  {
    new void GetClassID([Out] out Guid classID);
    void Initialize([In] IntPtr pidl);
  }
  
  [ComImport, Guid("1AC3D9F0-175C-11d1-95BE-00609797EA4F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  internal interface IPersistFolder2 : IPersistFolder
  {
    new void GetClassID([Out] out Guid classID);
    new void Initialize([In] IntPtr pidl);
    void GetCurFolder([Out] out IntPtr ppidl);
  }
  </code></pre>
  
  <p>I don't know why it works when I declare the COM interfaces that way (hidding the base interface methods using <code>new</code>). Maybe it is related to the way IUnknown works. Does anyone know what is the correct way of implementing COM interfaces in C# that inherits from other COM interfaces and why?</p>