I'm building a c# program that uses a local SQLite database to manage some simple data.
I am using the NuGet System.Data.SQLite (x64/x86) v1.0.98.0 - downloaded using the package manager console in Visual Studio Community 2015. Windows 7 64-bit.
I've built and debugged my code using the "Any CPU", x64, and x86 settings and it works fine. After I publish any of these versions though, I get the following error:
An unhandled exception of type 'System.DllNotFoundException' occurred in System.Data.SQLite.dll
Additional information: Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
The error occurs here:
SQLiteConnection.CreateFile("local-db.sqlite");
sqlite = new SQLiteConnection("Data Source=local-db.sqlite;Version=3;"); //Error on this line
Suggestions that haven't worked:
copying the bin/debug/x64 (and x86) folders (They contain versions of Interop.dll) up one directory
add SQLite.Interop.dll as a project reference (error - can't add as a reference)
add to project as existing item, set property "Copy to output directory = always". (still gets original error)
copying the most recent version of Interop.dll to the System.Data.SQLite directory (the directory referenced by my project)
At the very least, it's not failing to load the .dll but failing to find it. I don't know my way around dll's but it might work if I know where it's looking. Does anyone have a fix for this? There are a handful of related questions but they are either unanswered or don't work for me.
Related
It happened I am responsible for maintaining an older C# application. The application connects to a MySQL server and for some reason the MySql.Data.dll was included on disk and checked in.
So I thought on changing this to reference using a NuGET package. I removed the dependency on the checked in binary and added a package reference.
Now when I build the application I get the following error:
"path\myproject.csproj" (build target) (1) ->
(GenerateApplicationManifest target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3987,5): error MSB3113: Could not find file 'lib\MySql.Data.dll'.
I tried to find any occurrence of that dll but there seems to be no reference anymore.
How to stop the project referencing the non existing library?
The problem was, that even though I removed the dll within Rider the deployment reference (<Content ...) within the csproj file was not removed.
I've just installed Visual Studio 2019 with SDK and when i try to run RegPkg.exe, I see the following error. I don't have any other VS instances installed on the machine but I'm confused why the error is reporting about version 15.0.0.0 (which is VS2017).
Can someone please help me to resolve this error.
Unhandled Exception: System.IO.FileNotFoundException: Could not load
file or assembly 'Microsoft.VisualStudio.Shell.Framework,
Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
at Microsoft.VisualStudio.Tools.RegPkg.Main(String[] arguments)
I just noticed I got the exact same error message, using VS 2017's version. So it has nothing to do with the version you are using. I don't even have 2019 installed.
Microsoft simply broke their SDK, which has apparently been broken for 2 years, and no one noticed. For reference, I'm using VS 2017 15.9.7, also with the VSSDK installed.
I have a NuGet reference to that DLL in a VSIX extension I build, so I had a copy in my .nuget package cache ("%USERPROFILE%.nuget\packages\microsoft.visualstudio.shell.framework\15.9.28307\lib\net45\Microsoft.VisualStudio.Shell.Framework.dll"). I copied that version into the folder where regpkg.exe is located, and resolved the error (%VSSDK150INSTALL%\VisualStudioIntegration\Tools\Bin).
Probably not the best solution, but Microsoft needs to fix their product. I suspect it broke as part of their reorganization for the 2017 product, as they also added all the assemblies that extensions need for dependencies to NuGet. I guess they forgot to keep that assembly in the actual VS install folder.
EDIT: I've been looking into this more, and apparently the file actually exists in the lib sub folder right there with the exe. However none of the versions I've found actually work with CreatePkgDef.exe which was my backup plan, as it now throws this error instead:
CreatePkgDef : error : ArgumentException: No Visual Studio
registration attribute found in this assembly. The assembly should
contain an instance of the attribute
'Microsoft.VisualStudio.Shell.RegistrationAttribute' defined in
assembly 'Microsoft.VisualStudio.Shell.Framework' version '15.0.0.0'
Seems to work with regpkg.exe, though I haven't tried every combination of options.
I have run into this weird problem. In my WCF project I have referenced a class library that uses SQLite to query some static data. Naturally that class library is using System.Data.Sqlite + System.Data.SQLite.Core + System.Data.SQLite.EF6 + System.Data.SQLite.Linq from NuGet. The WCF project itself does not do the query. It invokes a method from the class library that does it.
When I run it on my dev machine all is well. But after I deployed it to IIS on a Windows Server 2012, the exception Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) was thrown. I did search SO and found that I need to reference at least System.Data.SQLite.Core in my main WCF project and make sure it has x64 & x86 folders with the corresponding Sqlite.Interop.dll in each folder respectively. The said folders are auto-generated with the NuGet reference and are placed under bin folder. So I was happy. Deployed. And same thing happened: all is well in dev machine then unable to load DLL on the server.
I even tried referencing all NuGet packages in main WCF project to no avail. Then it occurred to me to try manually copying the dll from x64 folder to my bin root folder, right alongside wcf.dll and System.Data.SQLite.dll. Now the error message changed to Unable to load DLL 'SQLite.Interop.dll': Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) instead of not found.
After giving it all permissions, it worked!
But this behaviour strikes me as strange because in my dev machine and another test server I cannot reproduce this. Only on the prod server would this error be thrown.
Is there anything that I've overlooked? BTW I tried to turn my WCF project from targeting AnyCPU to x64 only. I tried using Enable 32-bit in the advanced setting of IIS AppPool. None worked until all DLLs are in bin root.
I might be onto something here. I did a procmon. It seems to me that the dll under x86 was found successfully. It's however, denied access on a CreateFile operation.
Now it looks like it falls onto the permission realm. On Test environment and my dev machine the AppPool has god's privilege so the problem can't be reproduced.
TL;DR
Then I went into the permission detail. I found that WCF apppool identity has Read permission only on x86\Sqlite.Interop.dll. I added the Read and execute and problem gone. You millage may vary and it could be the x64 one that needs permission.
After thoughts:
Now I'll take a few days to observe but I think that this is it. Although from procmon it says Create File failed it doesn't mean it requires write permission.
Further testing showed my permission setting was off because I used the Visual Studio Deploy feature to deploy my website. In the process it sets my website root directory to Read only.
I am currently writing a desktop application (nothing hosted in IIS or similar, .NET 4.5.2) which makes use of SQLite and the Entity Provider for SQLite. For this to get it to work in Visual Studio, I had to install the 1.0.65.0 version package from the SQLite site to get the EF6 provider for SQLite inside Visual Studio. This worked as expected ad as far as I understood, this is also the only way this can be done.
For my application, I would like to use the current version which is 1.0.104.0 (again, info from the sqlite page). I have successfully added the Nuget package for this version to my application and when I look into the references tab, I can see System.Data.SQLite, System.Data.SQLite.EF6 and System.Data.SQLite.Linq, all with the version 1.0.104.0 and Specific Version set to True. Copy Local is set to true for all three of them.
So now when I run my application and get to the line:
using (var ctx = new SmtAoiLookupEntities())
{
foreach (var lu in ctx.Lookups.Where(d=>!string.IsNullOrEmpty(d.Aoi)))
{
...
}
}
I get the following error message:
An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll and wasn't handled before a managed/native boundary
Additional information: Could not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
From this, I understand that my application tries to load version 1.0.65.0, although all my references point to 1.0.104.0. I have absolutely no idea where my application gets the idea that I want to load 1.0.65.0. I even did a find in files to catch any reference to "1.0.65" with absolutely no results.
I used
gacutil -l System.Data.SQLite
to see which Assemblies are stored in the GAC -> Version 1.0.104.0
Now, this appears only to happen when I run the application from within Visual Studio; If I run the application outside Visual Studio as an executable I get a different error when saving the context. It appears that this is an application error and not related to the assembly version problem. I have also tried setting the application to a 32bit application, the issue stays the same.
The main issue: I would like to be able to debug the application inside Visual Studio, otherwise this could become quite cumbersome. Any ideas how I tell Visual Studio not to load the 1.0.65.0 libs?
A project in your solution is still pointing to previous SQLite version. In my case it was the project which file was throwing the error. Making sure every project in the solution has the updated package version solved the problem for me.
I'm trying to work out how to use ADO.Net Sqlite in VS2012 Express with no luck.
Things im doing from begining:
Starting new project and installing "System.Data.SQLite (x86/x64)" via NuGet for solution.
Adding using System.Data.SQLite; to directives.
Writing simple code like:
SQLiteConnection sql_sck = new SQLiteConnection("Data Source=test.sqlite;Version=3;New=False;Compress=True;");
Everything seems to look okay, VS recognize class names and changes their colors. However after running the program, in the sql_sck... line, exception is raised - about missing dll ?
An unhandled exception of type 'System.DllNotFoundException' occurred in System.Data.SQLite.dll
Additional information: Could not load DLL 'SQLite.Interop.dll': Could not find specified module. (Exception HRESULT: 0x8007007E)
Any ideas how can I make this work ? Is there anything I've done wrong / any steps missing ?
Somewhere Visual Studio will have created SQLite.Interop.DLL. You need to find that DLL and copy it to the same directory as your application's executable.
I usually add Interop DLLs to my project as a reference and flag them for copying to the output directory in order to ensure that others that use the projects don't forget the manual step.