Unable to load DLL 'SQLite.Interop.dll'

2019-01-02 17:26发布

Periodically I am getting the following exception:

Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I am using 1.0.82.0. version, installing it with nuget in VS2010, OS Win7 64.

Once exception starts to appear, it appears constantly - in debug and release and running application within or outside VS.

The only way to stop it is logoff and logon. The exception is not thrown and dll is loaded. It can work for days, but then it can break again.

Has anyone seen something like this and is there a solution for it?

30条回答
只靠听说
2楼-- · 2019-01-02 18:12

Also added the dll to the test project (through Nuget Manager) and it fixed it.

查看更多
荒废的爱情
3楼-- · 2019-01-02 18:13

Copy SQLite.Interop.dll in project directory.

src\
  project\
      bin\   <-- Past in bin
         x64\
           SQLite.Interop.dll <-- Copy this if 64
         x86\
           SQLite.Interop.dll <-- Copy this if 32
查看更多
冷夜・残月
4楼-- · 2019-01-02 18:14

I had this same problem when using SQLite in a WPF project whose platform target was Any CPU. I fixed it by following the following steps:

  1. Open the project designer in Visual Studio. Details on how to do it can be found here.
  2. Click on the Build tab.
  3. Disable the prefer 32-bit option.

Alternatively, you could just set the platform target to x86 or x64. I think this problem is caused by the System.Data.SQLite library using the platform target to get the location of the 'SQLite.Interop.dll' file.

UPDATE:

In case the project designer cannot be reached, just open the project (*.csproj) file from a text editor and add the value <Prefer32Bit>false</Prefer32Bit> into the <PropertyGroup>...</PropertyGroup> tag.

Example code

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>[Set by Visual Studio]</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>[Set by Visual Studio]</RootNamespace>
    <AssemblyName>[Set by Visual Studio]</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>[Set by Visual Studio]</FileAlignment>
    <!--Add the line below to your project file. Leave everything else untouched-->
    <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
查看更多
不流泪的眼
5楼-- · 2019-01-02 18:15

You could also get this error if you are trying to run a 32 bit dll, in a 64 bit project.

I got this when I have placed the same file(SQLite.Interop.dll in 32 bit version) in both the x86 and x64 folder.

查看更多
宁负流年不负卿
6楼-- · 2019-01-02 18:16

I am working on a simple console application to add some test data to an SQLite database and was getting this error. The configuration for the project is "Any CPU". I fixed it by copying the SQLite.Interop.dll to the bin\debug folder. A better way would be to use the method by @Wil, but how do you specify this for "Any CPU" configuration?

查看更多
流年柔荑漫光年
7楼-- · 2019-01-02 18:16

I have started using Costura.Fody to package (.net) assemblies and embed and preload native dlls. This also helps later, with distribution as you can send one file.

  1. Install Costura Fody from Nuget.

  2. In your C# project create a folder called costrua32. In there add any native dlls you which C# to load.

  3. Once you have added them to this folder. Click on the properties window and change build action to "Embedded Resource"

  4. Finally you need to amend the XML file called FodyWeavers.xml as follows. Here I am specifying load the sql dll first. (note you drop the .dll)

    Weavers
     Costura
      PreloadOrder
       SQLite.Interop
       tbb_debug
       tbb
      /PreloadOrder>
     /Costura
    /Weavers
    

The advantage of this is that you do not have to write any pre or post build events, and the end product is totally encapsulated in to one larger file.

查看更多
登录 后发表回答