SQLite Forum

[SOLVED] Add-Type : Could not load file or assembly 'System.Data.SQLite.dll'
Login

[SOLVED] Add-Type : Could not load file or assembly 'System.Data.SQLite.dll'

(1.1) By Julius (juliuspiv) on 2023-07-20 18:25:35 edited from 1.0 [source]

I'm trying to test out a PowerShell 7 script that relies on System.Data.SQLite.dll but am having trouble loading the DLL.

I installed SQLite using PowerShell via: Install-Module -Name sqlite

This seemed to install everything into: C:Program FilesWindowsPowerShellModulesSQLite2.0

I updated the script to use the System.Data.SQLite.dll in the binx64 directory then ran the following command to load it: Add-type -Path "C:\Program Files\WindowsPowerShell\Modules\SQLite\2.0\bin\x64\System.Data.SQLite.dll"

But that failed with: Add-Type: Could not load file or assembly 'C:\Program Files\WindowsPowerShell\Modules\SQLite\2.0\bin\x64\System.Data.SQLite.dll'. A dynamic link library (DLL) initialization routine failed. (0x8007045A)

Thinking it might be a bitness problem I retried using the x32 version of the DLL (found in both bin and binx32) but both failed with a slightly different error: Add-Type: Could not load file or assembly 'System.Data.SQLite, Version=1.0.77.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139'.

I'm unclear on what I might have done wrong and am in search of guidance from the community. System details: Windows 11 v22H2 x64, PowerShell 7.3.5

Many thanks!

(2) By Larry Brasfield (larrybr) on 2023-07-14 04:43:09 in reply to 1.0 [link] [source]

The DLL that you attempted to load probably depends upon SQLite.Interop.dll, and that was not loadable. So the overall load attempted by Add-Type failed.

I have no trouble with Add-type -Path ./System.Data.SQLite.dll when SQLite.Interop.dll is present in the same directory.

(3) By Julius (juliuspiv) on 2023-07-20 18:25:25 in reply to 2 [link] [source]

Thanks for taking the time to reply, I do appreciate it. Apologies for the delay in responding.

I think I've sorted this out. In short I needed to install Systme.Data.SQLLite.Core via NuGet and copy the two files from "%ProgramFiles%PackageManagementNuGetPackagesStub.System.Data.SQLite.Core.NetStandard.1.0.118.0" into the directory.

Many thanks!