How to Load Dll 'Sqlite.Interop.Dll'

Unable to load DLL 'SQLite.Interop.dll'

So, after adding the NuGet the deployment doesn't copy down the Interops. You can add this to your csproj file and it should fix that behavior:

 <PropertyGroup> 
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>

If you look in the source for NuGet for SQLite you can see what these are doing specifically. This allowed me to get a deploy working with ASP.Net Core.

Unable to load DLL 'SQLite.Interop.dll

I solved this problem by reference : https://stackoverflow.com/a/28092497/7352168+

Copy x86 and x64 SQLite.Interop.dll to IIS directory.

Visual Studio C# - SQLite.Interop.dll not found

See Using Native Library Pre-Loading at https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

You likely need to include the x86 and x64 folders under the the other SQLite DLL.

Edit: I've added the relevant info below in case the above link ever dies/changes.

If the development and customer machines may have different processor
architectures, more than one binary package may be required. For this
situation, using the native library pre-loading feature is highly
recommended. It is available as of version 1.0.80.0 and enabled by
default. In order to take advantage of this feature, the separate
managed and interop assemblies must be used with XCOPY deployment
(i.e. this feature is not supported by the mixed-mode assembly, nor
when the assembly is deployed to the global assembly cache), resulting
in an application deployment that looks something like this:

  • bin\App.exe (optional, managed-only application executable
    assembly)
  • bin\App.dll (optional, managed-only application library
    assembly)
  • bin\System.Data.SQLite.dll (required, managed-only core
    assembly)
  • bin\System.Data.SQLite.Linq.dll (optional, managed-only
    LINQ assembly)
  • bin\System.Data.SQLite.EF6.dll (optional,
    managed-only EF6 assembly)
  • bin\x86\SQLite.Interop.dll (required,
    x86 native interop assembly)
  • bin\x64\SQLite.Interop.dll (required,
    x64 native interop assembly)

The string "bin" above represents the directory where the application
binaries are to be deployed on the target machine. With the native
library pre-loading feature enabled and the application deployment
shown above, the System.Data.SQLite managed-only assembly will attempt
to automatically detect the processor architecture of the current
process and pre-load the appropriate native library.

Unable to load DLL 'SQLite.Interop.dll' error on client machine

I found a workaround for my issue. I already had correctly installed all of the SQLite packages, yet the Interop.dlls were not copying over when I published the application.

What I did was build the project, and then went into the bin/Debug/ folders and copied the x86 and x64 folders that contained the SQLite.Interop.dll files. I then included those folders in my project. All if working fine now.

Unable to load DLL 'SQLite.Interop.dll' from x64/x86 but is able to load the one alongside System.Data.SQLite.dll

I might be onto something here. I did a procmon. It seems to me that the dll under x86 was found successfully. It's however, denied access on a CreateFile operation.
Sample Image

Now it looks like it falls onto the permission realm. On Test environment and my dev machine the AppPool has god's privilege so the problem can't be reproduced.

TL;DR
Then I went into the permission detail. I found that WCF apppool identity has Read permission only on x86\Sqlite.Interop.dll. I added the Read and execute and problem gone. You millage may vary and it could be the x64 one that needs permission.

After thoughts:
Now I'll take a few days to observe but I think that this is it. Although from procmon it says Create File failed it doesn't mean it requires write permission.

Further testing showed my permission setting was off because I used the Visual Studio Deploy feature to deploy my website. In the process it sets my website root directory to Read only.

Sample Image

“Unable to load DLL 'SQLite.Interop.dll' or one of its dependencies” running an application in Docker, but locally it works fine

I ended up switching to Linux containers.



Related Topics



Leave a reply



Submit