A set of technologies in the .NET Framework for building web applications and XML web services.
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
- Re-register the DAO COM Library (DAO360.dll)
Most likely, the DAO.DBEngine is relying on DAO360.dll. To re-register it:
- Open Command Prompt as Administrator
- Run the following command:
Adjust the path if you're on a 32-bit system or have Office installed elsewhere.regsvr32 "C:\Program Files (x86)\Common Files\Microsoft Shared\DAO\DAO360.DLL" - You should see a confirmation that the registration succeeded.
- Ensure Correct Office / Access Database Engine is Installed
Make sure the correct Access Database Engine is installed, especially if your app uses DAO.
- Download from Microsoft:
- 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
- Set Platform target to
- Right-click the project > Properties > Build tab
- 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
- 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.DBEngineinterface.
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:
orcssCopyEditMicrosoft DAO 3.6 Object LibraryMicrosoft Office XX.X Access database engine Object Library
Hope this helps.