clarity on “AnyCPU/x64/x86” for Class not registered Exception RRS feed

  • Question

  • Here is my scenario: I am migrating a windows application which was built on VS2005/VS2008(not sure on which it was built). Objective of the migration is the windows application should run in Windows 10 OS systems.I am using VS2013 now. upgraded the Frame work version from 2 to 4.5.1. We are using an interop dll(lets say interop.xyz dll) for communication with MQ(not sure what this is).Don't have the source code the interop.xyz. Don't know is it supporting both 64/32 bit versions. Below is the code snippet where I am getting an exception

    colResults = new xyz.QueryResultCollection();

    Below is the exception.

    Retrieving the COM class factory for component with CLSID {690CFE43-BBB9-11D2-B60E-00203544F994} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

    After searching in online forums I found that I should register the interop.xyz dll. I tried many ways to register(tried regsrv.exe in cmd(for both System32/SysWOW64).But the registration was not successful). I thought the interop.xyz dll was built to support only 32 bit machines.

    After doing some more searching I found the solution to the issue. I have changed the platform target from "anyCPU" to "x86". Then i could open the application which out issues. But now my major concern is if I deploy this source code in WINDOWS 10 OS machines,will the application work? If not then how could I register the dll instead of changing the target platform.

    I am not sure what I am doing is correct. The application which I am migrating now was last modified in 2010 and there is no-one to give me any information about the application. I am just left alone to work with. Someone please suggest me a proper way to handle my current issue so that it should work in WINDOWS 10 OS systems. Thanks in advance. Note: My current VM specs---> Windows 7 64 bit OS

    Friday, November 10, 2017 7:09 AM

All replies

  • If the dll name contains interop, that is a signal that it might be 32bit dll. You can also check inside the bytes of the dll. Skip the first 128 bytes (0x80 bytes). Skip another 4 bytes. Check the next 2 bytes:

    • 4C 01 = 32bit dll
    • 64 86 = 64bit dll

    Now about AnyCPU/x64/x86 compilation...

    A compiled program with AnyCPU will run as 64bit on a 64bit system and as 32bit on a 32bit system.

    A compiled program with x64 will run only on a 64bit system.

    A compiled program with x86 will run on both systems, but even on a 64bit system will run as 32bit.

    So this raise your issue:

    If you use AnyCPU on a 64bit machine, the main program will run as 64bit and the dll is 32bit and it is a mismatch.

    If you use AnyCPU on a 32bit machine, the main program will run as 32bit and the dll also as 32bit and the application will work.

    The solution is to compile as x86 the main program, so you can use the dll on both Windows10 32bit or Windows10 64bit. You don't need to worry, it will run also in a 64bit system. There are plenty of applications that still run as 32bit on 64bit systems. It will take a while until all the applications will be 64bit.

    More about COM classes:

    When the DLL (32bit or 64bit) is registered, the class is added to HKEY_CLASSES_ROOT for both architectures, but also the path to the dll is stored. So behind, the dll is accessed by the main program and an architecture mismatch will lead to "Class not registered".

    • Edited by Colin Bursat Friday, November 10, 2017 12:53 PM
    • Proposed as answer by Weiwei Cai Monday, November 13, 2017 2:34 AM
    Friday, November 10, 2017 12:42 PM
  • Thanks for reply. But I have another issue. I built my source code as "x86" as you suggested and Checked in the code. I asked my team member to get latest from TFS and I tested the same in her system. She is getting the same error mentioned as above(coz the target platform is "anyCPU" by default).Then We changed the platform as x86 and tried running the app from source code, still got the same error. Then I searched GUID "690CFE43-BBB9-11D2-B60E-00203544F994" in my system's registry and found the below as shown in screenshot.Interop dll registration

    The thing is before posting the query i tried so many way to register the interop dll that the application is using. But every time i tried i got unsuccessful message. Then I gave up on registering the dll. But I am not sure how it got registered. Now I am trying to register the dll in my teammate's VM. But I am not able to register it. So not able to run the application from source code in my teammates system. All this while I thought registering the interop dll is not necessary. Could you please tell me what is dll registration and why it is important and what is the correct way to register the interop dll.

    Tuesday, November 14, 2017 2:40 PM
  • And I couldn't see "4C 01" or"64 86"(I opened the dll in notepad /checked the properties of dll/other stuff, but couldn't find what you suggested.) that you mentioned the reply.
    Tuesday, November 14, 2017 2:40 PM
  • Hi,

    >> Could you please tell me what is dll registration and why it is important

    Following thread introduce what does registering a DLL do. It will tell you why we need to register a dll.


    >> what is the correct way to register the interop dll.

    We often use regasm to register dll. You mentioned that you registered failed before, could you tell us the detailed steps you do and what error message you get.

    You could refer to below document to register dll.


    Best Regards,

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Weiwei Cai Tuesday, November 21, 2017 4:45 AM
    Wednesday, November 15, 2017 8:04 AM