Locating relevant dll versions for different runtimes in C# (DllNotFoundException from Sqlite)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hecksa

I’m trying to use Sqlite with C#. I’m getting a DllNotFound exception when running the project from the editor:

System.DllNotFoundException: e_sqlite3 assembly:<unknown assembly> type:<unknown type> member:(null)

As you can see, it’s failing to find e_sqlite3.dll, which has multiple versions for different platforms. In the Debug build output directory, all the other DLLs I’m using live in one place, but e_sqlite3.dll is split into different versions per architecture - it looks a bit like this:

- bin
    - Debug
        - MainGameProject.dll
        - Microsoft.Data.Sqlite.dll
        - ...a few other dependencies...
        - runtimes
            - win-arm/native
                - e_sqlite3.dll
            - win-x64/native
                - e_sqlite3.dll
            - win-x86/native
                - e_sqlite3.dll

If I copy the e_sqlite3.dll for my system (win-x64) and paste it into the Debug directory, all is well, but I feel like I’m probably doing something wrong in my project file or somewhere else in order to cause this.

For reference, my project file:

<Project Sdk="Godot.NET.Sdk/3.3.0">
  <PropertyGroup>
    <ProjectGuid>{209CA65A-C9E1-4DC2-ACC5-30EEFE8E6010}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>DeeElsie</RootNamespace>
    <AssemblyName>DeeElsie</AssemblyName>
    <TargetFramework>net472</TargetFramework>
    <!--The following properties were overriden during migration to prevent errors.
    Enabling them may require other manual changes to the project and its files.-->
    <Deterministic>false</Deterministic>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.1" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System" />
  </ItemGroup>
</Project>

Does anyone have any idea what I might need to tweak to get Godot to locate the relevant version of the dll itself?

I’m having the same problems sadly; did you find a workaround by any chance?
Currently it is working in debug for me with the dll at:
GODOTVERSION\GodotSharp\Mono\bin
However, I’m hesitant to use any packages that exhibit the same problem. For all I know it only runs fine on my system in debug mode.

Nighteyes | 2022-05-24 22:34

I’m afraid not, I just manually copied+pasted the files across whenever I needed to until I removed the dependency for a different approach a while ago.

If it’s a major problem for you it might be worth creating a Github issue for it at this point, especially since they’re reworking the .NET stuff so heavily right now for Godot 4, which might make now a good time to get it looked at.

Hecksa | 2022-05-24 22:50

Just saw your reply after my edit, thanks!
I can work around it with dictionaries and hashsets since I won’t need a big database. However, I rather use the correct tool for the job.
I will probably make a github issue tomorrow since there are more packages that have this problem (quite sure it was the JSONSerializer). For that one I used the older Newtonsoft JSONSerializer. Hope it gets fixed in version Godot 3.5; not sure how many hours it takes to migrate from Godot 3 to 4.

Nighteyes | 2022-05-24 23:04

Created a github issue here:
Nuget packages get DLL not found · Issue #61404 · godotengine/godot · GitHub

Nighteyes | 2022-05-25 23:14

:bust_in_silhouette: Reply From: juppi

You did a nuget restore or dotnet restore ?

Godot works with at least dotnet core 3.1 .
Newer dotnet Versions have the “dotnet cli”. Just open a terminal and use the command. Dotnet will then download the package for SQL Lite from the online store.

https://docs.microsoft.com/en-us/dotnet/core/tools/

Yes, when I first installed the package it was downloaded - that’s how the dll and associated folder structure in the question is able to get there in the first place. I also have run dotnet restore a few times to ensure there’s no issues with that - definitely doesn’t seem to be an issue related to nuget as far as I can tell.

Thanks for the response all the same, much appreciated :slight_smile:

Hecksa | 2022-01-31 01:46

This took me a little while to hunt down on my own, so I’m gonna post here in case someone else goes on a wild journey like I did.

I wanted to get a dev-able version of my program running on Windows AND Linux
Godot 3.5 frontend, C# backend, Sqlite database.

I ended up diagnosing that Godot was actually looking for the binaries in the wrong place by using ProcMon to find the launch options and log files
(in AppData\Roaming\Godot\mono)

Meanwhile, I also had difficulty getting a nice dev environment on Linux for C#

So I ended up getting MonoDevelop
Swapping out System.Data.SQLite (latest) for Microsoft.Data.Sqlite 2.2.0
running SQLitePCL.Batteries_V2.Init(); explicitly before new-ing an SqliteConnection object (it’s unnecessary from a function standpoint, but it makes the debugging more obvious what went wrong)
And then post-build moving the e_sqlite3.dll file to where Godot expects it to be, by adding this to my .csproj file

  <Target Name="GodotRunSqlHack" AfterTargets="Build">
    <Copy
	  Condition="Exists('$(TargetDir)/x64/e_sqlite3.dll')"
      SourceFiles="$(TargetDir)/x64/e_sqlite3.dll"
      DestinationFolder="$(TargetDir)" />
  </Target>

inside the Project tags

And

  • I still need to manually copy the e_sqlite3.dll when exporting to Windows.
  • Linux export still doesn’t work

But at least I got it to the point now where I can dev and “run” on both

(PS: if you wanna get the target os in msbuild, godot will pass $(GodotTargetPlatform) as a variable)