Lesson 3: Interoperating with COM
The purpose of this lesson is to expand upon the backwards-compatibility feature set of .NET to include COM "interop." This lesson makes explicit the relationship .NET has with legacy technologies like VB6. It may help to mention that COM stands for component object model, where the word "component" often indicates the physical boundary in which properties and procedures reside (effectively, this means a .DLL file).
- "When you add a reference to a COM object, Visual Studio automatically generates an interop assembly for the object and places it in the project's /bin folder."
This assembly can be viewed with Intermediate Language Disassembler (ILDASM.exe). For more information, see "VS.NET Tools: Intermediate Language Disassembler(ILDASM)" at:
http://www.c-sharpcorner.com/vsnet/IldasmTool.asp
- "Visual Basic 6.0 allowed you create COM properties (Property Let procedures) that were assigned by reference. Visual C# won't recognize those properties."
This looks like yet another very subtle difference between VB.NET and C#.
- "Visual Studio can automatically generate type library information and register a .NET class library assembly for use from COM. These automatic tools do not work for ASP.NET Web applications."
One could argue that ASP.NET applications are already interoperable with COM by default since Internet Information Server must still have COM interfaces at least up to version 6.0.
- "The ComVisible attribute allows you to select which public .NET classes and members are included in the generated type library."
One design pattern shown in the lesson sets the entire assembly to 'hidden' with:
[assembly: ComVisible(false)]
so that members can "opt in" to COM visibility.
- ".NET handles errors through exception classes. COM handles errors through 32-bit data types called HRESULTs."
Managed exceptions under COM are mapped to the appropriate HRESULT and vice versa.
- "COM requires objects to be created before use, so it does not support .NET Shared/static members."
This limitation stands out foremost for managed code running under COM among the lack of support for construtors with parameters and "shadow" members not being callable.