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

前端 未结 3 1835
灰色年华
灰色年华 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条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-11 16:06

    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.

提交回复
热议问题