Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

.net - "Register for COM Interop" vs "Make assembly COM visible"

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
{
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"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 a COM client can find it back. Which only uses a number to identify the object he wants to create, the GUID, an extra lookup is necessary to find out what DLL implements it. Registering involves writing keys in the HKLMSoftwareClassesCLSID{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. It is desirable since it ensures that the old copy of the DLL gets unregistered automatically before it is overwritten, that prevents registry pollution. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...