tags:

views:

609

answers:

4

Hi guys,

What is the Difference between .NET components and COM Components, sometimes we use .NET Components to include in our projects and sometimes we include COM reference. What is the idea behind? Thanks in advance.

+3  A: 

.NET components are managed code (memory disposal is done for you)

COM is an interface standard for software components. COM components are unmanaged code (memory disposal is performed using reference counting).

From here:

How are COM and .NET related?

COM and .NET are complementary development technologies. The .NET Common Language Runtime provides bi-directional, transparent integration with COM. This means that COM and .NET applications and components can use functionality from each system. This protects your existing investments in COM applications while allowing you to take advantage of .NET at a controlled pace. COM and .NET can achieve similar results. The .NET Framework provides developers with a significant number of benefits including a more robust, evidence-based security model, automatic memory management and native Web services support. For new development, Microsoft recommends .NET as a preferred technology because of its powerful managed runtime environment and services.

Mitch Wheat
Managed versus unmanged is not really a difference. You could have COM components created in a .NET language as well. The question as such is not perfeclty correct, because .NET components and COM components are not complementary.
0xA3
You can use regasm to consume any .NET component from COM; it's still a .NET component though...
Mitch Wheat
@Mitch: I think you should correct your answer. Still many COM components are written in VB6 which uses reference counting to handle memory disposal automatically. That's why your point COM==unmanaged vs. .NET==managed is not correct.
0xA3
@divo: I have updated. COM=unmanaged in the .NET CLR sense of the word. Your answer kind of implies that COM components written in VB6 can't leak memory, which is incorrect.
Mitch Wheat
@Mitch: How would reference counting imply that there are no memory leaks? And even in .NET you are not protected from having leaks.
0xA3
Btw, COM components are not necessarily implemented using unmanaged code. As you said, COM is an interface standard (ok, that's just nitpicking ;-)
0xA3
+2  A: 

.NET components run in the CLR, whereas COM components are essentially native Windows DLL's.

.NET components also expose vastly more metadata than COM components. This redesign was undertaken in part to make components more interoperable. In particular, .NET components do not make platform-specific assumptions about data layout and calling conventions.

It's also worth noting that the CLR itself is, in fact, implemented using COM.

See Don Box.

harpo
Is the CLR really written using COM? I know a lot of the framework libraries are wrappers around existing COM libraries but is the actual runtime itself using COM libraries?
sipwiz
A: 

COM components are unmanaged C++ code components designed to make software reusable at binary level. NET components are similar altough 1) they can be created on CLR-languages while COM components can be built with C++ only 2) They are meant to run under a managed runtime. I think those are essential differences.

EDIT:

C++ is the most "natural" language in COM, but COM components can be created in MANY languages. Thanks for the comments people.

Hernán
This is not quite true. COM components can be created in many different languages, among them C++, VB, and .NET languages such as C# or VB.Net
0xA3
VB? I don't use that since 5.0 days but that may be true. How can VB handle e.g those pointer-to-pointer parameters for some COM functions?
Hernán
divo I researched and you're right ;)
Hernán
Actually, VB 6 is *the* COM language (in a sense that VB is totally build around COM, obviously it is not as powerful as C++ but it offers the simplest way to work with COM objects)
0xA3
+1  A: 

Some more information about this topic

CCW : http://msdn.microsoft.com/en-us/library/f07c8z1c.aspx

RCW : http://en.wikipedia.org/wiki/Runtime_Callable_Wrapper

Shoban