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 states that it is used "if this project is exposed to COM".
None of my assemblies contain types which need to be visible to COM, so I have marked my assembly with [assembly: ComVisible(false)]
. So is there any point in specifying a GUID?
My feeling is that the answer is "no" - so why does the default AssemblyInfo.cs file contain both [assembly: ComVisible(false)]
and [assembly: Guid("...")]
?
Edit:
To summarize the responses:
Between them, the answers explain that specifying a GUID is required if and only if COM interop is being used. So, in my situation, a GUID is not necessary.
sharptooth further explains that [assembly: ComVisible(false)]
does not imply not using COM interop, since it is possible to override ComVisible
for individual types. It is for this reason that the default AssembyInfo.cs contains both [assembly: ComVisible(false)]
and a GUID.
Guid (Globally unique identifier) is used to identify your component by outside world. When you write a project which is going to be used as COM (Component Object Model) you will have to give a unique name. For this reason you need to apply GUID attribute.
Having [assembly: ComVisible(false)]
and [assembly: Guid("...")]
at the same time makes perfect sense in certain cases. You start with an empty assembly and will perhaps want to expose something from it to COM. So you mark the assembly as not ComVisible
and later mark the entities to expose as ComVisible
. That is why the GUID exists by default.
Regardless, if you really don't want to expose anything from your assembly to COM leave the "Register for COM interop" option unchecked in the project settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With