warning MSB3391: does not contain any types that can be unregistered for COM Interop

前端 未结 3 1853
灰色年华
灰色年华 2021-01-11 15:37

I\'ve made a simple C# DLL (that\'s part of a much larger project) using VS2005. I need to use the DLL in Excel via VBA code so I am using COM Interop on the assembly. I a

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-11 15:58

    1. You need to have ctor without any params.
    2. You should have GuidAttribute and ProgIdAttribute around the classes.
    3. Its better to mark the assembly as ComVisible(false) and mark explicitly the classes that need export.
    4. Use interfaces for your classes.
    5. Make sure the you have GuidAttribute in the assembly level.

      [Guid("")]
      [ComVisible(true)]
      interface IFoo
      {
          void DoFoo();
      }
      
      [Guid("")]
      [ComVisible(true)]
      [ProgId("ProgId.Foo")]
      class Foo : IFoo
      {
          public void DoFoo()
          {
          }
      }
      

提交回复
热议问题