-2

I have a project which I used to create the handling of a SqLite3 database. This project gets consumed by multiple other projects which in turn gets consumed by the UI project. I only added the Nuget package to the project handling the SqLite3 interfacing.

When I attempt to run the UI, it makes calls to get information from the database, and when this happens I get a System.DllNotFoundException for SQLite.Interop.dll.

So how do I force this to work without having to add the Nuget package to all the projects in the solution?

kw1jybo
  • 142
  • 1
  • 8
  • Create a Project that handles all database queries and add the needed classes to it to be used by the other projects. – Edney Holder Jul 09 '19 at 19:06
  • Possible duplicate of [Build NuGet Package automatically including referenced dependencies](https://stackoverflow.com/questions/16173568/build-nuget-package-automatically-including-referenced-dependencies) – Siderite Zackwehdex Jul 09 '19 at 19:08
  • I think this is a duplicate, see if the answer you seek is in that link. – Siderite Zackwehdex Jul 09 '19 at 19:08
  • I don't see how this helps. This is talking about creating a new package. What I am doing is referencing a packing in a.dll and when I run b.dll which references a.dll it gives me the dll not found issue – kw1jybo Jul 09 '19 at 19:13
  • I also don't see how it's a duplicate of that question. @kw1jybo tell us more about the project using the package. Is it a SDK style project or not? Is it WinForms, WPF, something else? If it's not SDK style, are you using PackageReference or packages.config? What's the target framework? – zivkan Jul 10 '19 at 01:53
  • @kw1jybo Hi friend, any update for this issue? – LoLance Jul 11 '19 at 05:48
  • I tried a number of things short of adding it to the main UI project, including specifying the build platform target from ANY to x86 and x64, and also disabled the prefer 32-bit. No joy. I find it disconcerting that I should have to add the package to the UI project and that it wouldn't be brought in when I reference it. When I look in the /bin dir of the project the dll in question is present, but there is also a dll.config and a System.Data.SQLite.xml file (don't know if those play a role or not....) – kw1jybo Jul 11 '19 at 18:16
  • @kw1jybo According to other similar issues, what the UI project needs is the `SQLite.Interop.dll` for corresponding platform, so you don't need the dll.config and .xml file I think. – LoLance Jul 15 '19 at 05:23

1 Answers1

0

Maybe your issue is similar to this one which often occurs when using Sqlite in WPF projects.

It seems that SQLite uses the entry assembly to detect which version of Interop to load.

And for your situation, the easy ways you can try to resolve it (Make the backup first):

  1. Right-click your UI project=>Properties=>Build=>disable the Prefer 32-bit or change the platform target from Any CPU to X64 or X86.

enter image description here

  1. You don't have to add the nuget to all your projects in the solution, adding it to the UI project(The main project which is set as StartUp project in your solution) is enough I think.

  2. Also, you can try Wil's answer,what you need to do is: create x64 and x86 folders in your UI Project Directory(where the xx.csproj exists)=>find and copy the SQLite.Interop.dll for x64 and x86 to corresponding folders. Then in VS, right-click UI project=>unload UI project and edit xx.csproj=>copy the working-version script into the xx.csproj file, and reload the UI project.(copy the ItemGroup script within <Project> tag)

Remember to rebuild the project before you run the app.

LoLance
  • 25,666
  • 1
  • 39
  • 73