Over the past couple of weeks I was working on building a custom DLL extension for Excel that I wrote in C# and built as a COM object with COM interop enabled through Visual Studio. The DLL itself works fine but I want to understand the technology behind it.
After reading a few articles and posts I got confused quite a bit and can't seem to find the information that explains exactly how COM and the .NET Framework work together to allow us to build these DLLs and why we need both of them.
My current understanding:
COM - a way to create binary objects that are language-independent and can be used in different environments. (For example you write a C# object, build it as a COM object, and then you can use it in your VB Script in Excel)
.NET Framework - a framework that provides a common run-time environment for all supported languages and allows language interoperability between them. (In other words a C# object can be used by a VB Script due to the CLR)
The Confusion:
In one of the articles COM was presented as a predecessor to the .NET Framework that requires a lot of extra logic from developers in order to manage their code(COM => unmanaged code). The .NET Framework takes care of that now and has a way to deal with unmanaged code as if it were managed code under the .NET Framework.
If COM and .NET Framework objects are technically cross-language compatible, why can't we simply use Visual Studio to build a C# DLL, build it and reference it in Excel as an add-in? Why do we need to register the assembly as COM object and enable it for COM interop if the .NET framework should already provide this language interoperability and all the code management features?
Perhaps it would be best if you can really explain the relationship between the 2 technologies and how exactly the "make assembly COM visible" and "register for COM interop" settings in Visual Studio tie in together with them.
Thanks, Dimitar
EDIT:
Update 04/22/19:
After reading your feedback below I get the following:
COM allows DLLs to expose their components by implementing some specific interfaces/methods
Excel only supports COM, and therefore only works with COM objects although it's a .NET Application.
.NET provides COM interop for applications such as Excel that cannot work with .NET components directly
The COM visible setting tells COM which parts of your object you want to be available for COM use. The COM interop decorates the C# object with the necessary interfaces/methods in order to make it usable by COM.
Things I still need clarified:
1.Is my C# object in Visual Studio considered a .NET component if not COM enabled? I assume yes.
2.Is COM interop the main thing that turns Excel into a .NET application?
Does the .COM interop also allow .NET applications that do not rely on COM, unlike Excel, to also use COM objects?
What exactly does the language neutralization? COM or .NET? How?