9

I have an Mvc application, and I have this option:

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

I do not know what this can do, is a security settings?

When to select ComVisible(false) and when ComVisible(true)?

I search for for Com components, to understand what this is, and I found this definition:

Component Object Model (COM) is a binary-interface standard for software components introduced by Microsoft in 1993. It is used to enable inter-process communication and dynamic object creation in a large range of programming languages. COM is the basis for several other Microsoft technologies and frameworks, including OLE, OLE Automation, ActiveX, COM+, DCOM, the Windows shell, DirectX, UMDF and Windows Runtime.

What this means for me is, that Com components is a way to communicate between applications, but I am not sure that my understanding of this definition is the rigth one.

Can you tell me in simple words(example), why and when should I make ComVisible(true)?

Liam
  • 27,717
  • 28
  • 128
  • 190
Lucian Bumb
  • 2,821
  • 5
  • 26
  • 39
  • 3
    Doesn't the quote in your question tell you the answer? – Enigmativity Jun 23 '16 at 08:44
  • The comment is not clear for me, this is why I post the question. This is why I was searching to understand what this actually mean. – Lucian Bumb Jun 23 '16 at 08:47
  • In general you don't want ComVisible(true), all the [headaches](http://stackoverflow.com/questions/3309764/why-is-marking-an-assembly-comvisibletrue-discouraged) and lack of generic [support](http://stackoverflow.com/questions/134633/is-it-possible-to-implement-a-com-interface-with-a-net-generics-class?rq=1) means you'll only set it up when somehow your library need to be called by non .NET app. – Martheen Jun 23 '16 at 08:47
  • 2
    COM isn't used very widely anymore. It's a technology from 1993! Having written and used COM components I can tell you they are a massive pain to install, configure and maintain. Typically things like service level arcitecture have replaced this installing of interoperative dll's approach now. If your not sure wether you should set it then you almost defineately shouldn't. – Liam Jun 23 '16 at 08:53
  • Also, using MVC means your app is interoperable with any OS anyway through REST or OData, no need to support ancient Windows-only just because .NET was initially born in a world with large COM ecosystem. – Martheen Jun 23 '16 at 08:56
  • 1
    I think the [microsoft web site on COM](https://www.microsoft.com/com/default.mspx) (repleat with man in a fetching green 90s suit looking like a bad extra from an early Friends episode) tells you all you need to know about COM in the modern era ha ha – Liam Jun 23 '16 at 08:56

1 Answers1

13

You set the ComVisible property to true, when you need to expose public methods and functions in your assembly to other applications not written in .NET, which can then use the functionality in your assembly using Microsoft's COM, a standardized interface that binds to components at runtime.

Further reading: https://blogs.msdn.microsoft.com/cristib/2012/10/31/how-com-works-how-to-build-a-com-visible-dll-in-c-net-call-it-from-vba-and-select-the-proper-classinterface-autodispatch-autodual-part12

Example: https://richnewman.wordpress.com/2007/04/15/a-beginner%E2%80%99s-guide-to-calling-a-net-library-from-excel

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77