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

不问归期 提交于 2019-12-01 03:44:57
  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("<PUT-GUID-HERE-1>")]
    [ComVisible(true)]
    interface IFoo
    {
        void DoFoo();
    }
    
    [Guid("<PUT-GUID-HERE-2>")]
    [ComVisible(true)]
    [ProgId("ProgId.Foo")]
    class Foo : IFoo
    {
        public void DoFoo()
        {
        }
    }
    

I saw a similar problem. I got an error like:

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

I followed all the rules (ComVisible, etc.) but nothing worked.

Solution: I had to put something in the default constructor so that it would not be optimized away. The moment I had something there, the registration finished with no message and the component was visible in the registry.

Interesting note: a friend of mine managed to register the original DLL with the empty default constructor on his machine (64-bit Windows-7, VS2008-Professional, like mine). However, his REGASM.EXE was:

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe

while mine was:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe

So it could be some difference between versions of the .NET framework - maybe the later version is optimizing too much and the REGASM does not account for that.

NotMe

In the AssemblyInfo.cs file, make sure you have the following:

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

UPDATE:

Read: How can I make use of .NET objects from within Excel VBA?

Which links to: http://richnewman.wordpress.com/2007/04/15/a-beginner%E2%80%99s-guide-to-calling-a-net-library-from-excel/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!