Re: Q: ComVisible and CLSCompliant

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Brian Tyler (brianmtyler_at_yahoo.com)
Date: 06/11/04


Date: Fri, 11 Jun 2004 12:18:28 -0500

I think you are operating under the misunderstanding that .NET is built on
top of COM. That is not true* (although I believe that some parts, such as
the C++ profiling API, are exposed via COM). However, due to the incredibly
large amount of COM objects out there today, MS spent a lot of time and
effort making it easy to interoperate between the two - but you don't have
to if you don't want to...so, just put down that COM book and back away
slowly :)

Here is the quick-n-dirty rule, just as in the CLS attribute: If you don't
plan to access your .NET objects from VB6 or unmanaged C++, you can safely
ignore the ComVisible attribute (or just set it to false globally - I do
this in my AssemblyInfo.cs file).

* disclaimer - I don't work for MS so I can't say how the deep internals are
written, but I don't see a lot of evidence of much COM going on inside the
CLR...

"Jiho Han" <jiho.han@infinityinfo.com> wrote in message
news:eJu$Km8TEHA.2464@TK2MSFTNGP10.phx.gbl...
> I see. Maybe it's my lack of understanding of COM that is preventing me
> from fully understanding this attribute's usage.
> It feels like even in the age of managed environment, COM still follows me
> to haunt me. Do you suppose COM will always be there underneath .NET,
> hidden, perhaps even into the era of Longhorn?
> Do you think that COM will be relevant enough to read a book on it
perhaps?
> something like Essential COM by Don Box?
>
> Thanks for making things clearer though.
> Jiho
>
> "Brian Tyler" <brianmtyler@yahoo.com> wrote in message
> news:%23o99YF8TEHA.3660@tk2msftngp13.phx.gbl...
> > Designing a COM-friendly interface is a bit more challenging than just
> > making a .NET type public. It is typically recommended that if you want
to
> > expose your functionality to COM, that you should create specific COM
> target
> > type that wraps your .NET classes and use the ComVisible attribute to
only
> > expose those that make sense (keeps your COM TBL cleaner also). See
> >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconexposingfunctionalitytocom.asp
> >
> >
> >
> > As for CLSCompliant, it is really only an issue if you are trying to
> create
> > libraries to be shared among different languages. For example, if you
are
> a
> > C# developer but are creating libraries for other teams that are VB.NET
> > programmers, you definitely want to set this attribute. If you have a
> stand
> > alone app it really doesn't have any value.
> >
> >
> >
> > That help?
> >
> >
> >
> > Brian
> >
> > "Jiho Han" <jiho.han@infinityinfo.com> wrote in message
> > news:uxiYvb7TEHA.3528@TK2MSFTNGP12.phx.gbl...
> > > Maybe it's a practical example I need to understand the need for
> > ComVisible.
> > > You can only apply the attribute to public types anyway. And when you
> > make
> > > a type public, you do so with the intent to publish the interface
> > > "publicly". In what situations, would you want to hide a type from
COM
> > > only?
> > >
> > > As for CLSCompliant attribute, it's still a little unclear. I say
> > > informational because it tells the VB code that uses a component
> developed
> > > in C#, that the component doesn't use types like UInt32. Is that what
> you
> > > mean?
> > >
> > > Thanks much!
> > >
> > > "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
> > > news:utinXG1TEHA.3828@TK2MSFTNGP09.phx.gbl...
> > > >
> > > > >Setting ComVisible(false) on the assembly level is said to hide the
> > > assembly
> > > > >to the COM system. What does that accomplish? Is that simply in
> place
> > > to
> > > > >prevent others from TlbExp'ing?
> > > >
> > > > And to help you not to accidently expose things to COM that
shouldn't
> > > > be.
> > > >
> > > >
> > > > >And what about CLSCompliant attribute? Is that simply for
> > informational
> > > > >purposes only?
> > > >
> > > > No, compilers can generate warnings or errors if your public types
and
> > > > members that are marked as CLSCompliant in fact use features that
> > > > aren't CLS compliant.
> > > >
> > > >
> > > >
> > > > Mattias
> > > >
> > > > --
> > > > Mattias Sjögren [MVP] mattias @ mvps.org
> > > > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> > > > Please reply only to the newsgroup.
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: Q: ComVisible and CLSCompliant
    ... from fully understanding this attribute's usage. ... > libraries to be shared among different languages. ... > C# developer but are creating libraries for other teams that are VB.NET ... >> As for CLSCompliant attribute, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Are bad developer libraries the problem with M$ software?
    ... Rather than trying to take advantage of "secure libraries" on any given OS, ... developer of potential issues. ... And if designers of any language are going to ...
    (SecProg)
  • RE: Are bad developer libraries the problem with M$ software?
    ... >>I have never been able to fathom why compilers can't barf out better ... Secure Windows Initiative ... Are bad developer libraries the problem with M$ software? ...
    (SecProg)
  • Re: Pointer Problem
    ... His version and your 'assert' suggestion is annoying ... enough that a developer seeing his message will nudge or force them to ... far from the origin of the defect itself. ... Standard libraries choke silently on NULL arguments, ...
    (comp.lang.c)
  • Re: It Hurts When I Do This
    ... Being an old libraries guy (I used to do compiler run-time libraries before working on compilers themselves), I'd have suggested moving this code to a library routine - just pass it the descriptors of the LHS and RHS. ... But adding a library routine isn't without cost - it creates support headaches when users try to link objects with older libraries. ... I was a compiler developer for 15 years. ...
    (comp.lang.fortran)