Mono SQLite上的System.DllNotFoundException

时间:2014-01-22 20:18:23

标签: c# sqlite mono dllnotfoundexception

我最近一直试图解决这个问题。它正在我的Windows机器上工作,我从NuGet获得SQLite,但是......

当我将System.Data.SQLite.dllSQLite.Interop.dll直接从我的Windows计算机放入Linux服务器时,它说SQLite.Interop.dll未找到,但我确信我接下来会看到它可执行。< / p>

然后我尝试用System.Data.SQLite.dll编译/p:UseInteropDll=false,但没有运气。这次它说没有找到System.Data.SQLite.dll

这个“未被发现”的谜团是什么?

5 个答案:

答案 0 :(得分:10)

无需更改代码。你可以自己构建它。

  1. apt-get install build-essentials unzip
  2. 下载SQLITE源代码 - 您需要完整的源代码。目前称为sqlite-netFx-full-source-1.0.104.0.zip
  3. unzipcd Source
  4. chmod +x compile-interop-assembly-release.sh构建shell脚本,然后运行./compile-interop-assembly-release.sh。 - 它将在.so目录中构建一个../bin文件。
  5. 将此.so文件复制到包含您的应用程序的目录中
  6. 正常运行您的应用程序。
  7. 注意:确保您尝试运行的用户可以写入您的SQLite数据库及其内部的目录。

答案 1 :(得分:7)

在Linux上使用Mono.Data.SQLite.dll。请查看Mono手册至using SQLite on Linuxbuild the System.Data.SQLite.dll on Mono

您还可以映射DLL:

<configuration>
  <dllmap dll="sqlite" target="libsqlite.so.0" os="linux"/>
  <dllmap dll="sqlite" target="libsqlite.0.dylib" os="osx"/>
  <dllmap dll="sqlite3" target="libsqlite3.so.0" os="linux"/>
  <dllmap dll="sqlite3" target="libsqlite3.0.dylib" os="osx"/>
</configuration>

答案 2 :(得分:5)

我在Windows中开始开发,但随后将应用程序移动到Mono(Ubuntu 14),这是SQLite提供程序无法按OP描述加载的地方。

我不得不使用以下命令重新编译System.Data.SQLite.dll:

MSBuild System.Data.SQLite.2012.csproj /t:Rebuild /p:UseInteropDll=false /p:UseSqliteStandard=true 

然而,在此之后我得到以下例外:

  

提供程序未返回ProviderManifest实例。   方法System.Data.SQLite.UnsafeNativeMethods:GetSettingValue (string,string)' is inaccessible from method System.Data.SQLite.EF6.SQLiteProviderManifest:GetProviderManifestToken(string)'

要解决此问题,我必须使用以下命令重新编译System.Data.SQLite.EF6.dll:

MSBuild System.Data.SQLite.EF6.2012.csproj /t:Rebuild /p:UseInteropDll=false /p:UseSqliteStandard=true

将所有生成的文件复制到Mono项目的bin目录后,一切正常。

我使用的SQLite提供程序源代码版本是1.0.98.1。

希望这可以节省很多时间......

答案 3 :(得分:1)

我尝试了上述所有选项,但这些选项无法解决SQLite DLL问题,可能是因为我使用的是ubuntu 18版本,所以尝试了其他选项,并在此处进行了操作,

1)从https://system.data.sqlite.org/downloads/1.0.111.0/sqlite-netFx-full-source-1.0.111.0.zip

下载SQLite源代码

2)解压缩源代码,并 cd解压缩目录

3)在终端中运行以下命令,

xbuild / p:Configuration =发布/ p:UseInteropDll = false / p:UseSqliteStandard = true ./System.Data.SQLite/System.Data.SQLite.2010.csproj

4)上面的命令将在以下路径中创建一个dll文件,

sqlite-netFx-full-source-1.0.111.0 / bin / 2010 / ReleaseMonoOnPosix / bin

5)将System.Data.SQLite.dll复制到项目bin文件夹。

6)清理项目并重新构建。

我希望这会有所帮助。

答案 4 :(得分:0)

System.Data.SQLite.Core 1.0.109开始,由于所有平台(Linux,macOS和Windows)的本机SQLite.Interop.dll文件都包含在NuGet软件包中,因此您不需要自己编译任何东西。请注意,尽管dll扩展名用于所有平台,但文件实际上是本机动态库(在macOS上后缀 dylib ,在Linux上后缀 so )。 / p>

$ find ~/.nuget/packages/system.data.sqlite.core/1.0.111/runtimes -name SQLite.Interop.dll -print0 | xargs -0 file
…/runtimes/linux-x64/native/netstandard2.0/SQLite.Interop.dll: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=96ce4120b31bad7d95f7b9ccf7c4bbb7717ae0b1, with debug_info, not stripped
…/runtimes/osx-x64/native/netstandard2.0/SQLite.Interop.dll:   Mach-O 64-bit dynamically linked shared library x86_64
…/runtimes/win-x86/native/netstandard2.0/SQLite.Interop.dll:   PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
…/runtimes/win-x64/native/netstandard2.0/SQLite.Interop.dll:   PE32+ executable (DLL) (GUI) x86-64, for MS Windows

不幸的是,负责将本机动态库复制到输出目录中的MSBuild目标仅在Windows上有效。这可能是因为该软件包的作者假定.NET Framework仅在Windows上运行,这要归功于Mono。另外,如果您想看看,可以在CopySQLiteInteropFiles中找到~/.nuget/packages/system.data.sqlite.core/{version}/build/net4*/System.Data.SQLite.Core.targets目标。

但是可以将SQLite.Interop.dll文件自动复制到Linux和macOS的输出目录中。在您的csproj文件中添加FixSQLiteInteropFilesOnLinuxAndOSX目标(如下所述),您将能够在不带DllNotFoundException且运行单声道的Linux和macOS上使用System.Data.SQLite.Core。这是您的项目外观:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net452</TargetFramework>
  </PropertyGroup>
  <Target Name="FixSQLiteInteropFilesOnLinuxAndOSX" BeforeTargets="CopySQLiteInteropFiles">
    <ItemGroup>
      <SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(Linux)) OR $([MSBuild]::IsOsPlatform(OSX))" Remove="@(SQLiteInteropFiles)" />
      <SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(Linux))" Include="$(PkgSystem_Data_SQLite_Core)/runtimes/linux-x64/native/netstandard2.0/SQLite.Interop.*" />
      <SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(OSX))" Include="$(PkgSystem_Data_SQLite_Core)/runtimes/osx-x64/native/netstandard2.0/SQLite.Interop.*" />
    </ItemGroup>
  </Target>
  <ItemGroup>
    <PackageReference Include="System.Data.SQLite.Core" Version="1.0.111" GeneratePathProperty="true" />
  </ItemGroup>
</Project>

确保在软件包参考中添加GeneratePathProperty="true"。这是定义PkgSystem_Data_SQLite_Core属性所必需的。