1

I'm writing a Unity Plugin in C#, that use SQLite.

The SQLite dependency to SQLite.Interop.dll, as I'm understanding this is a unmanaged DLL.

When I export my Unity plugins, there are several DLL files were exported along with my plugin.

Bin folder
|
|_ MyPlugin.dll
|_ System.Data.SQLite.dll
|_ (other files)
|_ x86
|   |_ SQLite.Interop.dll
|
|_ x64
|   |_ SQLite.Interop.dll

When using in the Unity game project, I put all the files under Assets/Plugins/MyPlugin as below:

Assets
|
|_ Plugins
    |_ MyPlugin
         |_ MyPlugin.dll
         |_ System.Data.SQLite.dll
         |_ (other files)
         |_ SQLite.Interop.dll (x64 version)

In Unity editor, everything is OK, I can establish SQLite connection and do the transaction.

However, when exporting the Unity project to standalone application for Windows x64, it doesn't work and it throws error say that DllNotFoundException.

System.DllNotFoundException: SQLite.Interop.dll
at (wrapper managed-to-native) System.Data.SQLite.UnsafeNativeMethods:sqlite3_config_none (System.Data.SQLite.SQLiteConfigOpsEnum)
  at System.Data.SQLite.SQLite3.StaticIsInitialized () [0x00000] in <filename unknown>:0 
  at System.Data.SQLite.SQLiteLog.Initialize () [0x00000] in <filename unknown>:0 
  at System.Data.SQLite.SQLiteConnection..ctor (System.String connectionString, Boolean parseViaFramework) [0x00000] in <filename unknown>:0 
  at System.Data.SQLite.SQLiteConnection..ctor (System.String connectionString) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Data.SQLite.SQLiteConnection:.ctor (string)
  at MyPlugin.Service.Util.SqliteBase.InitConnection () [0x00000] in <filename unknown>:0 
  at MyPlugin.Service.Util.SqliteBase.OpenConnection () [0x00000] in <filename unknown>:0

The folder structure of standalone application is as below:

Output
|_ UnityApp.exe
|_ UnityApp_Data
    |
    |_ Managed
    |    |_ MyPlugin.dll
    |    |_ System.Data.SQLite.dll
    |    |_ (other DLLs)
    | 
    |_ Plugins
         |_ SQLite.Intedrop.dll

The DLL is there but seem that Unity doesn't find it.

I found the solution to modify PATH environment variable here https://stackoverflow.com/a/33124250

It works, but I wonder if there is anything wrong with my configuration or is there any reason why Unity doesn't load SQLite.Intedrop.dll although it's existing in the application data folder.

I'm very appreciated any helps.

EDIT 1: The SQLite DLL is got by NUGET:

<package id="System.Data.SQLite" version="1.0.106.0" targetFramework="net35" />
<package id="System.Data.SQLite.Core" version="1.0.106.0" targetFramework="net35" />
<package id="System.Data.SQLite.Linq" version="1.0.106.0" targetFramework="net35" />
Tien
  • 2,105
  • 17
  • 14

1 Answers1

1

You put the native plugin in the wrong folders.

Put the 32-bit dll plugin in Assets/Plugins/x86.

Put the 64-bit dll plugin in the Assets/Plugins/x86_64.

Make sure to also include any dependencies otherwise you will still see the-same error.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Even when I tried to put files in the folder as you said, it doesn't change anything. As you can see, in the output application, the structure contains the DLL but it still doesn't work. – Tien Apr 25 '18 at 08:04
  • Do these things: 1.Show a screenshot that shows where you put the dlls. 2.Show the line of code with DllImport that causes that error. 3.Provide a link to where you got the dll. If I have these I may be able replicate your issue or find the issue right away from these information – Programmer Apr 25 '18 at 08:52
  • 1. You can check where the dlls is in the structure I draw in my question. 2. My plugin uses System.Data.SQLite.dll. The SQLite.Intedrop.dll is referenced and used by System.Data.SQLite.dll. 3. I got it from NUget package, you can see in my question. – Tien May 11 '18 at 10:49