Why does using SQLite in Azure Functions give me a DLLNotFoundException?

3

I'm trying to write a timer-triggered Azure Function that downloads a bunch of data and processes it into a SQLite database. I've written code that does this and runs fine on my own machine. But, the same code in Azure yields a DllNotFoundException, complaining that the system can't load "e_sqlite3."

Here is the full error message (for the inner exception):

Exception while executing function: FnordFunction

Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: FnordFunction ---> System.TypeInitializationException : The type initializer for 'SQLite.SQLiteConnection' threw an exception. ---> System.DllNotFoundException : Unable to load DLL 'e_sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

at SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_libversion_number()

at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()

at SQLitePCL.raw.SetProvider(ISQLite3Provider imp)

at SQLitePCL.Batteries_V2.Init()

at SQLite.SQLiteConnection..cctor()

End of inner exception

Here are the steps to reproduce:

  1. In Visual Studio 2017, I created an Azure Function project using the latest template.
  2. I added my code files to the project, and edited the "Run" method to call the code.
  3. Using NuGet, I added sqlite-net-pcl, and some other libraries I need. (I've also tried this with EntityFrameworkCore, using SQLite; that didn't work either).
  4. Build
  5. Publish
  6. Run. Failure.

The problem might be that my code is wrong--but it works fine when I just make a console .exe.

The problem might be that VS2017 is not bundling the correct dll for SQLite when it builds. I'm not sure how to fix that. I've seen from other searches that the same error message pops up when the platform target is set to "Any CPU," but changing that to x86 or x64 does not fix the problem.

The problem might be that the SQLite libraries I have tried won't run in the Azure Functions sandbox. If so, are there any simple SQLite libraries that will run in the sandbox?

Thanks in advance...

c#
sqlite
azure
azure-functions
asked on Stack Overflow Apr 6, 2018 by jgfооt

1 Answer

7

The problem is that when running in a Function App, native binaries can't be automatically loaded from your bin folder, so it's not finding the DLL.

One way to solve this is to drop it in your D:\home\site\tools folder (e.g. using Kudu Console), as that folder is automatically place on the PATH.

answered on Stack Overflow Apr 7, 2018 by David Ebbo

User contributions licensed under CC BY-SA 3.0