❔ Default behavior of ComVisible attribute
While updating a legacy .NET framework application to net6, I ran into a question where I was unable to find an answer for:
What's the default behavior if I simply omit the ComVisible attribute from the AssemblyInfo? The doc says its default value is true but does that only apply when the attribute is set or will it also apply when I don't set the attribute at all? Does the compiler implicitly add anything like that?
5 Replies
The default is true, which indicates that the managed type is visible to COM. This attribute is not needed to make public managed assemblies and types visible; they are visible to COM by default. Only public types can be made visible. The attribute cannot be used to make an otherwise internal or protected type visible to COM or to make members of a nonvisible type visible.
ComVisibleAttribute Class (System.Runtime.InteropServices)
Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM.
i do believe the .NET SDK adds ComVisible(false) in a generated file
it is pretty easy to check by opening the assembly in ILSpy
okay, i lied, sorry. it does not
Thanks for the explanations. I somehow missed that part of the official docs
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.