3

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?

3
  • 2
    Run OleView (both x86 and x64) on the DEV server and verify you can create the object. Saying that it is registered is not enough particularly when the evidence appears to be otherwise Commented Apr 6, 2018 at 15:05
  • The TypeLib is there as well as the Interface, however it's not listed under Application Id's, where it is on other machines. How do I register this? Commented Apr 6, 2018 at 16:13
  • Got it, OleView was a huge help. Thank you. Commented Apr 6, 2018 at 22:24

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

.NET Core doesn't force you to be cross platform. You can certainly use it. You are right that then it will not run on all OS, but if you want to use COM in .NET Core and you target only Windows, you can certainly do it. There are limitations. I recently did a post using COM in .NET Core from Command Line, Windows Forms and ASP.NET Core: mobilize.net/blog/mauricios-blog-redux
2

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.

2 Comments

do you have sample of what you did. I have the same problem now. Thanks
Use OleView to create the neccessary class Id's and other registry entries (this part is the most involved). Next, take the DLL that you are attempting to register, if you have the source code, pull it into your project as normal, if you don't, decompile the source and generate a "stub" class in your project.
1

I've run into this recently, trying to instantiate an x86 coclass. Turns out that Visual Studio starts the first dotnet.exe which appears in the system path, no matter what architecture is actually configured. In my case, an x86_64 variant of dotnet.exe was started as a host, which in turn can't create any x86 coclass instances.

Try to load your project into the apropriate variant of dotnet.exe by hand and see if this helps.

Edit: This issue is discussed in more detail at https://github.com/dotnet/core/issues/901

Comments

0

As I can't comment yet.... You can use regsvr32 MyComLibrary.dll to add all the neccessary registry keys for you. See https://helpdeskgeek.com/how-to/register-dll-file-in-windows/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.