gpt4 book ai didi

c# - 为什么在 Azure Functions 中使用 SQLite 会出现 DLLNotFoundException?

转载 作者:行者123 更新时间:2023-12-02 02:41:21 26 4
gpt4 key购买 nike

我正在尝试编写一个计时器触发的 Azure 函数,该函数下载大量数据并将其处理到 SQLite 数据库中。我已经编写了执行此操作的代码,并且在我自己的机器上运行良好。但是,Azure 中的相同代码会产生 DllNotFoundException,提示系统无法加载“e_sqlite3”。

这是完整的错误消息(针对内部异常):

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

以下是重现步骤:

  1. 在 Visual Studio 2017 中,我使用最新模板创建了一个 Azure Function 项目。
  2. 我将代码文件添加到项目中,并编辑了“Run”方法来调用代码。
  3. 使用 NuGet,我添加了 sqlite-net-pcl 以及我需要的其他一些库。 (我还使用 SQLite 在 EntityFrameworkCore 上尝试过此操作;但这也不起作用)。
  4. 构建
  5. 发布
  6. 运行。失败。

问题可能是我的代码是错误的 - 但当我只制作一个控制台 .exe 时它工作正常。

问题可能是 VS2017 在构建时没有为 SQLite 捆绑正确的 dll。我不知道如何解决这个问题。我从其他搜索中看到,当平台目标设置为“任何 CPU”时,会弹出相同的错误消息,但将其更改为 x86 或 x64 并不能解决问题。

问题可能是我尝试过的 SQLite 库无法在 Azure Functions 沙箱中运行。如果是这样,是否有任何简单的 SQLite 库可以在沙箱中运行?

提前致谢...

最佳答案

问题是,在 Function App 中运行时,无法从 bin 文件夹自动加载 native 二进制文件,因此无法找到 DLL。

解决此问题的一种方法是将其放入您的 D:\home\site\tools 文件夹中(例如使用 Kudu 控制台),因为该文件夹会自动放置在 PATH 上。

关于c# - 为什么在 Azure Functions 中使用 SQLite 会出现 DLLNotFoundException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49701806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com