New SQLite mixed assemblies

不打扰是莪最后的温柔 提交于 2019-11-27 01:05:28

问题


Previously .NET SQLite libraries were available from http://sqlite.phxsoftware.com, but they have recently been taken over by the main SQLite team and have moved System.Data.SQLite Download Page. The new packages don't seem to contain mixed assemblies anymore (single assembly containing sqlite3.dll and the .NET wrapper).

The new package comes with the .NET DLL and SQLite.Interop.dll which based on the documentation is not needed on the desktop but my application fails to load with Unable to load DLL 'SQLite.Interop.DLL': The specified module could not be found.. I have tried running the application under IIS/IIS Express with apppool set to 32-bit.

I have tried copying the SQLite.Interop.dll file into the bin folder, the system folder, and the ASP.NET temp folder but still get the same error.

Are there mixed assemblies for new releases available anywhere? If not, is there a way to fix the Unable to load DLL 'SQLite.Interop.DLL error?


回答1:


The downloads page now contains "mixed mode" downloads for all variations of System.Data.SQLite, that work the same way as earlier versions of SQLite i.e. no requirement to also include SQLite.Interop.dll in your project.

The trick is - look for the word "bundle" in the download links

e.g. sqlite-netFx35-setup-bundle-x86-2008-1.0.76.0.exe

You will also see that the description text for these links begins with "This setup package features the mixed-mode assembly".

I got burned because I didn't realize that this really means "download this one if you want it to work the way it always did before".

Having no idea what was meant by a mixed-mode assembly, the other links seemed like a better option - because they claim "This setup package will install all the necessary runtime components and dependencies".

Also note that the only way to tell if you've gotten the "wrong" one is by file size. The DLLs have exactly the same name, and exactly the same version number. The mixed-mode version is much bigger - around 700K. The other one is around 160K.

What a mess...




回答2:


I found the solution. The problem was due to a known issue with SQLite.Interop.dll.

This is the workaround from that worked for me.

Using Dependency Walker from http://dependencywalker.com/ to look at SQLite.Interop.dll (x86 and x64) shows that it depends on MSVCR100.dll.

The old 1.0.66.0 version of System.Data.SQLite.dll does not have this dependency. With the current build, we would have to redistribute that MSVCR100.dll also or run an installer from Microsoft.

Solution: From: Missing msvcr100.dll

Use static linking. In the SQLite.Interop Visual Studio project. Go to this Properties setting: Project -> Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library and change the value to Multi-threaded (/MT). (The current source code (1.0.71.0) has Multi-threaded DLL (/MD) which causes the dll to rely on MSVCR100.dll and the DLLImport (and LoadLibary()) to fail when users do not have it).

I believe static linking should be changed so it is the default for SQLite.Interop.dll.




回答3:


I had the same issue, in a plugin for a different application. In my case I solved it by modifying the environment variable PreLoadSQLite_BaseDirectory before referencing SQLite for the first time.

// Make SQLite work... (loading dll from e.g. x64/SQLite.Interop.dll)
System.Environment.SetEnvironmentVariable("PreLoadSQLite_BaseDirectory", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

Sql.Data.SQLite...

I don't see why this was required though, as I thought PreLoadSQLite_BaseDirectory (well, the corresponding internal variable) would default to the location of the System.Data.SQLite.dll file.




回答4:


On 64-bit machines an AnyCPU targeted .NET application cannot load 32-bit DLL files. You likely will need to set the platform target of your .NET application to x86 in order to get it working on both the 64-bit and 32-bit machines.

Edit: under the hood the reason you can't load the Interop DLL is probably because of a BadImageFormatException due to the bitness mismatch with the native SQLite DLL file.



来源:https://stackoverflow.com/questions/6205393/new-sqlite-mixed-assemblies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!