Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using COM Object in .NET Core 2.0

So, a client has a COM object written in C from 2007 that validates an encrypted session cookie. This currently works fine with older versions of .NET using the following.

var validate = Activator.CreateInstance(Type.GetTypeFromProgID("Company.Validate"));

The new implementation will be entirely in C#. I've extracted validation logic to a .NETCore class library, which we in turn reference in our ASP.Net Core project.

  1. I've tried 32-bit & 64-bit versions, as well as IIS settings.

  2. I've decompiled the COM object and referenced that instead, it works locally, but not on the development server, where I receive the following error:

    Retrieving the COM class factory for component with CLSID {EDC43BC6-5ECD-4501-AEB3-64A17180A13D} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

  3. The COM is registered both locally and on the development server.

  4. Activator.CreateInstance does not work in either environment.

  5. The registered COM ID and ProgId is the same both locally and on the development server.


Q: What am I missing, or is this not going to work? Has anyone had any success with similar challenges? Am I overlooking anything?

like image 905
Ryan Avatar asked May 04 '26 03:05

Ryan


2 Answers

You can't use COM with .NET Core. COM is Windows-only and everything in .NET Core must be cross-platform. You can however run your ASP.NET Core application on the full framework, and then you can use the COM library. In other words, running the full framework doesn't preclude you from being able to still use ASP.NET Core. You simply will only be able to deploy to Windows, because of the full framework/COM dependency. Technically, you only need to use .NET Core if you're planning to deploy to something like a Mac or Linux. Otherwise, just stick to what you know.

like image 94
Chris Pratt Avatar answered May 05 '26 18:05

Chris Pratt


The required registry keys were never created. I had to manually add about 15 keys, for the Class, Interface, and Type. I believe this is because the COM had never been marshaled or invoked (because that wouldn’t work) so the Class ID, AppID and registry mapping’s had to be entered manually.

like image 33
Ryan Avatar answered May 05 '26 18:05

Ryan