Is there any point in specifying a Guid when using ComVisible(false)?

后端 未结 3 2140
庸人自扰
庸人自扰 2020-12-15 02:41

When you create a new C# project in Visual Studio, the generated AssemblyInfo.cs file includes an attribute specifying an assembly GUID. The comment above the attribute stat

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 03:21

    Consistent GUIDs are absolutely essential in COM. The [assembly:Guid] attribute generates the type library LIBID. Surely the project template auto-generates one to make sure that the programmer doesn't forget to provide one when s/he flips ComVisible to true.

    If an assembly [Guid] isn't provided then Tlbexp.exe synthesizes one from the assembly name, version and public key. That's not really good enough, type libraries already have a version. Changing [AssemblyVersion] would generate a different LIBID. Especially bad when you use the auto-increment option for the version (like 1.0.*), you could quickly fill the registry with a mountain of dead TypeLib registry keys.

    Long story short, it avoids a lot of nasty mishaps.

提交回复
热议问题