What are alternatives to generic collections for COM Interop?

After some more research and trial-and-error, I think I found a solution by using System.Collections.ArrayList. However, this does not work with getting a value by index. To do so, I created a new class ComArrayList that inherits from ArrayList and adds new methods GetByIndex and SetByIndex. COM Interop compatible collection: public class ComArrayList : System.Collections.ArrayList … Read more

How to make make a .NET COM object apartment-threaded?

You can inherit from StandardOleMarshalObject or ServicedComponent for that effect: Managed objects that are exposed to COM behave as if they had aggregated the free-threaded marshaler. In other words, they can be called from any COM apartment in a free-threaded manner. The only managed objects that do not exhibit this free-threaded behavior are those objects … Read more

Exposing Property as Variant in .NET for Interop

COM Automation supports a default property, the property that has dispid 0. This is used in VB6 code to great effect, generating really compact code. A typical example is: rs!Customer = “foo” Which is syntax sugar for: rs.Fields.Item(“Customer”).Value = “foo” Three default properties being used here without being named in the original statement. The Recordset … Read more

Type exists in 2 assemblies

I know this is old, but there’s an easier way than the listed. This works when you reference two assemblies that share types with the exact same name and namespace. If you right-click on the Reference to your DLL and select Properties, you will see that here’s a property called “Aliases” The default value is … Read more

unable to cast COM object of type ‘microsoft.Office.Interop.Excel.ApplicationClass’ to ‘microsoft.Office.Interop.Excel.Application'”

Microsoft Office 365 I was running Microsoft Office 365 with Windows 10 and tried the mentioned solutions to remove the registry key without success. I went to the control panel in an attempt to repair the Office 365 suite. Right Click on Start Menu Click Apps and Features Search Microsoft 365 Click Microsoft 365 Click … Read more