How to access a 32-bit COM dll from a 64-bit C# application?

James Allen 0 Reputation points
2025-12-09T17:52:10.66+00:00

I'm updating a WPF application that's written in C#. My development environment is Visual Studio 2023. The application currently uses .NET Framework 4.6.1, but I'm hoping to upgrade to a more modern version of .NET as part of the update.

The application uses a 32-bit COM dll, which I've called "DataTest" in the code below. This has been registered with regsvr32 and appears on the list of available COM objects in my project. When added to the "References" section, a DLL named "Interop.DataTest.dll" is created in my \obj directory, as expected.

The DLL exposes a single object, "CDataTest", with various properties and methods. I instantiate it as follows:

using System;
using DataTest;
namespace MyNameSpace.DataTest
{
    /// <summary>
    /// Wrapper for DataTest CDataTest object
    /// </summary>
    public class DataTest
    {
        private readonly CDataTest _dataTest;
        public DataTest()
        {
            _DataTest = new CDataTest();
        }
    }
}

This works correctly when I build the application in "x86" or "Any CPU" mode. However, I now need to access a new 64-bit DLL, so I need to build the application in "x64" mode. When I do so, I get the following exception when instantiating CDataTest:

System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {[GUID]} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

"GUID" is the GUID of the CDataTest object. Following the advice in another question on this site, I've added the following keys to my registry:

HKLM\Software\Classes\CLSID\{GUID}
HKLM\Software\Classes\AppID\{GUID}

The first key contains only a REG_SZ value "AppID" which is set to the GUID, the second key contains only an empty REG_SZ value "DllSurrogate". However, this hasn't fixed the issue.

A 64-bit version of "DataTest" or a 32-bit version of the new DLL are not available.

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.