Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ComVisible not working as advertised?

8 views
Skip to first unread message

Amos Wittenberg

unread,
May 15, 2003, 4:23:22 PM5/15/03
to
The documentation
<ms-help://MS.VSCC/MS.MSDNQTR.2002OCT.1033/cpref/html/frlrfsystemruntimeinteropservicescomvisibleattributeclasstopic.htm>
says:
<quote>
This example shows how you can control the visibility to COM of a
class so that only certain members are visible. Setting
ComVisibleAttribute to false on the class, and true on MyMethod and
MyProperty causes only those members to be visible to COM.
</quote>

... but it does not seem to work! I get "COM Interop registration
failed. There are no registrable types in the built assembly."

Does anyone have an idea what is going on? Is this a bug?

The reason I need this is: I am building an Automation Add-In for
Excel and I want to hide the Object methods. Hiding ToString() is not
a problem: I override it and then I can hide it. But GetType() is
sealed so this trick does not work. Creating my own GetType() (with
the "new" keyword) is fine and I can hide it alright but that just
results in Object's GetType() to appear again...

Anyone able to shed light?

Mattias Sjögren

unread,
May 15, 2003, 4:35:01 PM5/15/03
to
Amos,

>The documentation
><ms-help://MS.VSCC/MS.MSDNQTR.2002OCT.1033/cpref/html/frlrfsystemruntimeinteropservicescomvisibleattributeclasstopic.htm>
>says:
><quote>
>This example shows how you can control the visibility to COM of a
>class so that only certain members are visible. Setting
>ComVisibleAttribute to false on the class, and true on MyMethod and
>MyProperty causes only those members to be visible to COM.
></quote>

In the v1.1 docs, the topic now says

"The following example shows how you can control the visibility to COM
of a class so that its members are invisible. By setting
ComVisibleAttribute to false on MyClass, and false on MyMethod and
MyProperty, you can avoid inadvertently exposing the members to COM
through inheritance."


>The reason I need this is: I am building an Automation Add-In for
>Excel and I want to hide the Object methods. Hiding ToString() is not
>a problem: I override it and then I can hide it. But GetType() is
>sealed so this trick does not work. Creating my own GetType() (with
>the "new" keyword) is fine and I can hide it alright but that just
>results in Object's GetType() to appear again...
>
>Anyone able to shed light?

Define an interface with the members you want to expose, make your
class implement that, and apply the
[ClassInterface(ClassInterfaceType.None)] attribute to the class.

Mattias

===
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Amos Wittenberg

unread,
May 15, 2003, 5:14:15 PM5/15/03
to
Mattias

>In the v1.1 docs, the topic now says [snip]

In other words, a bug in the documentation ;-)

>Define an interface with the members you want to expose,
>make your class implement that, and apply the
>[ClassInterface(ClassInterfaceType.None)] attribute to
>the class.

Works a treat! Mr Sjögren, thou art a gentleman and a scholar! Do you
need some points in some appreciation contest? Send me the URL and
consider it done!

One curious thing: by accident I did not write "ImplClass:
ISneakyIntercase" and simply wrote "ImplClass", with the
[ClassInterface(ClassInterfaceType.None)] bit. Result? All the
beasties I wanted to hide were visible! GetType(), ToString(), you name
it. Slapping the interface implementation thingie on resulted in the
desired effect: beasties gone and all my beautiful methods gloriously
visible. Mind you, not a trace of the actual interface as far as I can
see. My names are Pds.Functions (class) and IFunctions (interface).
Pds.Functions.foo() works fine.

Magic, my Nordic saviour, sheer magic.

Thanks again.

Amos

===
Amos Wittenberg
Brevan Howard Services Ltd
London


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

0 new messages