-->

Unable to load DLL 'sqlite3' in SQLite Net

2019-04-04 17:13发布

问题:

I am in process of developing native app using Xamarin.Forms. But the problem I am facing now is not related with Xamarin. I added new Windows Phone project by

right-click > Add > New Project -> Windows Phone Apps -> Blank App(Windows Phone).

in my existing Xamarin project in Visual Studio premium 2013. I am using sqlitenet pcl for database connection. I have below code in my project.

public ISQLitePlatform CreateSqlitePlatformInterface()
        {
            return new SQLitePlatformWinRT();
        }

When it executes above line, it throws exception as

An exception of type 'System.DllNotFoundException' occurred in SQLite.Net.Platform.WinRT.DLL but was not handled in user code

Additional information: Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

This has been asked many many times and I tried all suggested solution, still I am not able to fix it.

My Packages.config

 <package id="SQLite.Net-PCL" version="3.0.5" targetFramework="wpa81" />
  <package id="Sqlite-Winrt" version="3.8.7.1" targetFramework="wpa81" />
  <package id="Xamarin.Forms" version="1.4.2.6359" targetFramework="wpa81" />

Above are the packages I downloaded from Nuget. Am I missing anything? What else I need to add?

Also I tried:

  1. Downloaded sqlite-winrt81-3081002.vsix from Sqlite download page.
  2. Copied sqlite3.dll from x86.
  3. Tried pasting it in my bin folder as well as in my project root and changed it content to copy always. (ref: https://stackoverflow.com/questions/4744293/unable-to-load-dll-sqlite3-the-specified-module-could-not-be-found-exceptio)
  4. My project is targeting x86 not Any CPU.

Tried suggested solution from: Sol1, Sol2

My Project References:

回答1:

After installing the SQLite Visual Studio Extension, you need to add a reference To the SQLite for Windows Runtime In Reference Manager under Windows / Extensions.

Like this.



回答2:

I experienced a different flavour of this error after some March 2016 updates to Windows 10 and Visual Studio 2015: my app would run fine when deployed to my desktop but crash with the System.DllNotFoundException (“Unable to load DLL 'sqlite3'") when deployed to my tablet (even after updating the tablets OS with the latest updates). So my steps to resolve the problem were as follows:

  1. Uninstalled the VS extension called “SQLite for Universal App Platform” (v3.10.2)
  2. Removed the reference to this extension from my project
  3. Installed the extension again--except this time it showed up in the online extensions list as “SQLite for Universal Windows Platform” (v3.12.1)
  4. Added the reference to this extension to my project
  5. (this is the important part, which I didn't need to do before): Added a reference to the "Visual C++ 2015 Runtime for Universal Windows Platform Apps” (v14.0) extension

It wasn't until that last step that it actually fixed the problem.