Share via

How to fix the error "InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'DAO.DBEngine'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00000021-0000-0010

Devi E 5 Reputation points
2025-01-30T12:22:58.2266667+00:00

Hi, I am trying to access DAO.DBEngine for an operation and getting the error " InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'DAO.DBEngine'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00000021-0000-0010-8000-00AA006D2EA4}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."

This was working fine, but recently we started receiving this error, can someone provide a suggestion to resolve this error

Developer technologies | ASP.NET | ASP.NET Core
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.


2 answers

Sort by: Most helpful
  1. Danny Nguyen (WICLOUD CORPORATION) 6,700 Reputation points Microsoft External Staff Moderator
    2025-07-21T08:49:55.87+00:00

    Hi,
    The error:

    InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'DAO.DBEngine' ... Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))

    is caused by a missing or corrupted registry entry for the DAO (Data Access Objects) COM library. Although your code worked previously, changes to the system — such as an Office upgrade, uninstall, registry cleanup, or Windows update — might have broken the registration of the DAO library.


    Steps to Fix the Issue

    1. Re-register the DAO COM Library (DAO360.dll)

    Most likely, the DAO.DBEngine is relying on DAO360.dll. To re-register it:

    1. Open Command Prompt as Administrator
    2. Run the following command:
         regsvr32 "C:\Program Files (x86)\Common Files\Microsoft Shared\DAO\DAO360.DLL"
      
      Adjust the path if you're on a 32-bit system or have Office installed elsewhere.
    3. You should see a confirmation that the registration succeeded.
    4. Ensure Correct Office / Access Database Engine is Installed

    Make sure the correct Access Database Engine is installed, especially if your app uses DAO.

    1. Check Target Architecture (x86 vs x64)

    If your application is compiled as x64 but the DAO library is only available as x86, you'll get COM interop errors.

    • Make sure your application is targeting the same architecture as the DAO components (often x86).
    • In Visual Studio:
      • Right-click the project > Properties > Build tab
        • Set Platform target to x86
    1. Reinstall or Repair Office / Access Runtime

    If the registry is too broken, reinstallation may help:

    • Go to Control Panel > Programs and Features
    • Locate your Office installation (or Access Runtime)
    • Click Change > choose Repair
    1. Manually Check Registry

    If comfortable, you can check the Registry:

    • Open regedit
    • Navigate to:

      HKEY_CLASSES_ROOT\Interface{00000021-0000-0010-8000-00AA006D2EA4}

    • If this key is missing or corrupt, the COM registration has failed. This GUID is the DAO.DBEngine interface.

    Safer DAO Access via Microsoft.Office.Interop.Access.Dao

    If you're accessing DAO.DBEngine via Interop in .NET, ensure you have the correct COM reference added in your project:

    • Right-click References > Add Reference > COM > Select:
        cssCopyEditMicrosoft DAO 3.6 Object Library
      
      or
        Microsoft Office XX.X Access database engine Object Library
      

    Hope this helps.

    1 person found this answer helpful.

  2. Bruce (SqlWork.com) 83,821 Reputation points
    2025-01-30T16:38:24.64+00:00

    The registry setting appears to not be correct. Install or repair access drivers install on the hosting server.


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.