views:

145

answers:

1

What is the real difference between these two options? What I know is:

Register for COM Interop
This options executes regasm on the assembly and registers the assembly as an COM component(or maybe not) in the registry with all COM like registry entries. Does this step generates a TLB file? What else is done?

Sometimes I see a tlb is generated when I compile the project but sometimes not, why is this?

Make assembly COM visible
What effect does this one has on an assembly? If I have the following type inside this assembly, do I still need to specify the "Make assembly COM Visible" even though my type is marked as ComVisible?

[GuidAttribute("02810C22-3FF2-4fc2-A7FD-5E103446DEB0"), ComVisible(true)]
public interface IMyInterface
{
}
+4  A: 

"Make assembly COM visible" is a big hammer to make all public types in the assembly [ComVisible]. Rarely desirable, you will want to select the specific types that you want to be visible, like you did in your snippet.

After the assembly is built, it needs to be registered so that it becomes usable by COM clients. This involves writing registry keys in the HKLM\Software\Classes\CLSID{guid} portion of the registry. You can do it yourself by running Regasm.exe /codebase /tlb or you can leave it up to the build system to do it automatically after building the assembly. Which is what "Register for COM interop" does. VS needs to run elevated to have write access to those registry keys, one reason for making it optional. Or you just don't want to register it, common on build servers. I can't comment on why you'd sometimes not get the .tlb without more diagnostics.

Hans Passant
+1. I guess one more reason for why it is optional is you don't always need to register the assembly on your daily build server. For example, you expose a C# assembly to COM and consume it from C++ via `#import` directive which is happy to use the .tlb file.
sharptooth
+1: I think by "all types in assembly [ComVisible]" you mean *all public types* because the public types are what I see in the exported TLB.
A9S6
Thanks, comments merged into the answer.
Hans Passant